使用FUSE在Python中创建临时文件

3

我正在尝试使用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!
< p > [编辑] 我找到了问题所在,我没有一个打开的方法,但即使如此,最终我还是将file_class取出来,实现在主FUSE类中的方法,因为那似乎更好用。

1
很高兴您找到了问题。请随意撰写自己的答案,并对其进行标记(这样问题就不会显示为未回答)。我认为您需要等待24小时才能回答自己的问题,所以您应该可以在大约5个小时后返回并执行此操作。 - mgiuca
1个回答

2

我最终发现问题是因为我在文件类中没有创建open()或create()方法,但最终我决定在主FUSE类中实现所有方法,因为文件类似乎对我没有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接