我正在使用python编写一个fuse文件系统,它应该与amazon S3交互(基本上将S3存储桶视为文件系统)并面临我的readdir实现的一些问题。
首先,我想提及我相对较新的python和融合(更多的java人,因为保险丝绑定的简单性,在这里使用python),所以这可能一切都只是一个愚蠢的初学者的错误..
这是我目前所拥有的:
def readdir(self, path, fh):
s3Path = S3fsUtils.toS3Path(path) # removes prefixed slash - boto3 can't handle that in key names
print("Reading dir: " + str(path))
retVal = [".", ".."]
for s3Obj in self.bucket.objects.all(): # for now list all objects in bucket
tmp = str(s3Obj.key)
if tmp.startswith(s3Path): # only return things below current path
print("READDIR: appending to output: " + tmp)
retVal.append(tmp)
return retVal # return directory contents as a list of strings
这是运行" ls -l" (文件系统安装在" / tmp / fusetest"):
root@michael-dev:/tmp/fusetest# ls -l
ls: reading directory .: Input/output error
total 0
root@michael-dev:/tmp/fusetest#
...这里是文件系统的控制台输出: (找到的条目是一些"目录",即没有数据的S3键)
Reading dir: /
READDIR: appending to output: blabla/
READDIR: appending to output: blablubb/
READDIR: appending to output: haha/
READDIR: appending to output: hahaha/
READDIR: appending to output: huhu/
READDIR: appending to output: new_folder/
Releasing dir: /
我猜测问题是我返回了一个字符串列表而不是更多的字符串列表" C-struct-like"事情... 我找到this question which is also about problems with readdir,有一个班级" fuse.Direntry"用来。但是,在我的fuse.py(fusepy版本= 2.0.2)中,我找不到这样的类,我找到的最接近的名字是" fuse_file_info"对于手头的任务来说,它看起来并不实用。
那么readdir应该返回什么以及i / o错误来自哪里?
答案 0 :(得分:1)
Ok, this turned out to be just what I expected - a stupid mistake...
Since Amazon S3 represents folders as empty files whose names end with a slash, my file listings contained a lot of entries with slashes at the end. It turned out, fuse cannot handle that, causing the readdir operation to fail.
Removing the slashes from the file names does the trick.