我正在尝试使用 python-fuse 编写程序,但我无法记录文件。我的 file_class 看起来像这样
class FuseFile(object):
def __init__(self, path, flags, *mode):
debug(path)
#debug(mode);
self.file = tempfile.TemporaryFile(*mode);
self.fd = self.file.fileno()
self.path = path
def write(self, buf, offset):
head, tail = os.path.split(self.path)
self.file.seek(offset);
self.file.write(buf);
return len(buf)
def read(self, length, offset):
file = apiCall("readfile",{"file":self.path}).read();
slen = len(file)
if length < slen:
if offset + size > slen:
size = slen - offset
buf = file[offset:offset+size]
else:
buf = ''
return file # I don't know if this buff stuff is necesarry...
def ftruncate(self, len):
self.file.truncate(len);
def release(self, flags):
self.file.close()
def flush(self):
self._fflush()
def fsync(self, isfsyncfile):
self._fflush()
if isfsyncfile and hasattr(os, 'fdatasync'):
os.fdatasync(self.fd)
else:
os.fsync(self.fd)
def _fflush(self):
if 'w' in self.file.mode or 'a' in self.file.mode:
self.file.flush()
但是当我尝试在像 VIM 这样的编辑器中编辑文件时,我得到了这个:
"mnt/stuff.txt" E514: write error (file system full?)
WARNING: Original file may be lost or damaged
don't quit the editor until the file is successfully written!
[EDIT]
我发现了问题,我没有 open 方法,但即便如此,我最终还是拿出了 file_class 来实现主 FUSE 类中的方法,因为这样似乎更好用