Use path_to_node for all operations.
This commit is contained in:
@@ -24,9 +24,14 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class IndexFS(LoggingMixIn, Operations):
|
class IndexFS(LoggingMixIn, Operations):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def path_to_node(path, index):
|
def path_to_node(path, index, directory_only=True):
|
||||||
|
logger.debug('path: %s', path)
|
||||||
|
logger.debug('directory_only: %s', directory_only)
|
||||||
|
|
||||||
parts = path.split('/')
|
parts = path.split('/')
|
||||||
|
|
||||||
|
logger.debug('parts: %s', parts)
|
||||||
|
|
||||||
directory = index.instance_root
|
directory = index.instance_root
|
||||||
|
|
||||||
if len(parts) > 1 and parts[1] != '':
|
if len(parts) > 1 and parts[1] != '':
|
||||||
@@ -34,11 +39,22 @@ class IndexFS(LoggingMixIn, Operations):
|
|||||||
try:
|
try:
|
||||||
directory = directory.children.get(value=part)
|
directory = directory.children.get(value=part)
|
||||||
except IndexInstanceNode.DoesNotExist:
|
except IndexInstanceNode.DoesNotExist:
|
||||||
print '{} does exists'.format(part)
|
logger.debug('%s does not exists', part)
|
||||||
try:
|
|
||||||
return directory.documents.get(label=part)
|
if directory_only:
|
||||||
except Document.DoesNotExist:
|
|
||||||
return None
|
return None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
result = directory.documents.get(label=part)
|
||||||
|
logger.debug('path %s is a valid file path', path)
|
||||||
|
return result
|
||||||
|
except Document.DoesNotExist:
|
||||||
|
logger.debug('path %s is a file, but is not found', path)
|
||||||
|
return None
|
||||||
|
|
||||||
|
logger.debug('directory: %s', directory)
|
||||||
|
#logger.debug('directory children: %s', get_children())
|
||||||
|
logger.debug('directory is root: %s', directory.is_root_node())
|
||||||
|
|
||||||
return directory
|
return directory
|
||||||
|
|
||||||
@@ -48,16 +64,17 @@ class IndexFS(LoggingMixIn, Operations):
|
|||||||
self.index = Index.objects.first()
|
self.index = Index.objects.first()
|
||||||
|
|
||||||
def getattr(self, path, fh=None):
|
def getattr(self, path, fh=None):
|
||||||
result = IndexFS.path_to_node(path=path, index=self.index)
|
now = time()
|
||||||
|
result = IndexFS.path_to_node(path=path, index=self.index, directory_only=False)
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
raise FuseOSError(ENOENT)
|
raise FuseOSError(ENOENT)
|
||||||
|
|
||||||
if isinstance(result, IndexInstanceNode):
|
if isinstance(result, IndexInstanceNode):
|
||||||
now = time()
|
return {
|
||||||
return dict(
|
'st_mode': (S_IFDIR | 0755), 'st_ctime': now, 'st_mtime': now,
|
||||||
st_mode=(S_IFDIR | 0755), st_ctime=now, st_mtime=now, st_atime=now, st_nlink=2
|
'st_atime': now, 'st_nlink': 2
|
||||||
)
|
}
|
||||||
else:
|
else:
|
||||||
now = time()
|
now = time()
|
||||||
|
|
||||||
@@ -73,19 +90,23 @@ class IndexFS(LoggingMixIn, Operations):
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
def open(self, path, flags):
|
def open(self, path, flags):
|
||||||
result = IndexFS.path_to_node(path=path, index=self.index)
|
result = IndexFS.path_to_node(path=path, index=self.index, directory_only=False)
|
||||||
|
|
||||||
if isinstance(result, Document):
|
if isinstance(result, Document):
|
||||||
self.fd_count += 1
|
self.fd_count += 1
|
||||||
|
|
||||||
self.fd[self.fd_count] = result.open()
|
self.fd[self.fd_count] = result.open()
|
||||||
return self.fd_count
|
return self.fd_count
|
||||||
|
else:
|
||||||
return None
|
raiseFuseOSError(ENOENT)
|
||||||
|
|
||||||
def read(self, path, size, offset, fh):
|
def read(self, path, size, offset, fh):
|
||||||
return self.fd[self.fd_count].read(size)
|
return self.fd[self.fd_count].read(size)
|
||||||
|
|
||||||
def readdir(self, path, fh):
|
def readdir(self, path, fh):
|
||||||
|
logger.debug('path: %s', path)
|
||||||
|
|
||||||
|
'''
|
||||||
parts = path.split('/')
|
parts = path.split('/')
|
||||||
|
|
||||||
directory = self.index.instance_root
|
directory = self.index.instance_root
|
||||||
@@ -95,9 +116,17 @@ class IndexFS(LoggingMixIn, Operations):
|
|||||||
try:
|
try:
|
||||||
directory = directory.children.get(value=part)
|
directory = directory.children.get(value=part)
|
||||||
except IndexInstanceNode.DoesNotExist:
|
except IndexInstanceNode.DoesNotExist:
|
||||||
print '{} does exists'.format(part)
|
logger.debug('%s does not exists', part)
|
||||||
raise FuseOSError(ENOENT)
|
raise FuseOSError(ENOENT)
|
||||||
|
|
||||||
|
logger.debug('directory: %s', directory)
|
||||||
|
'''
|
||||||
|
|
||||||
|
directory = IndexFS.path_to_node(path=path, index=self.index, directory_only=True)
|
||||||
|
|
||||||
|
if not directory:
|
||||||
|
raiseFuseOSError(ENOENT)
|
||||||
|
|
||||||
result = ['.', '..']
|
result = ['.', '..']
|
||||||
|
|
||||||
directories = directory.get_children().order_by('value')
|
directories = directory.get_children().order_by('value')
|
||||||
|
|||||||
Reference in New Issue
Block a user