creating a temporary file in python with FUSE
Asked Answered
I

1

3

I am trying to write a program using python-fuse, but I can't get file writing down. my file_class looks like this

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()

but when I try and edit the file in a editor like VIM I get this:

"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] I found the problem, I didn't have a open method, but even so, I eventually took out the file_class to implement the methods in the main FUSE class, because that seems to work better

Indivisible answered 27/6, 2011 at 11:40 Comment(1)
Glad you found the problem. Feel free to write an answer to your own question, and tick it off (so this question won't look unanswered). I think you have to wait 24 hours before you can answer your own question, so you should be able to come back and do this in about 5 hours.Bemire
I
2

I eventually found out that the probelm was that I hadn't created a open(), or create() method in my file class, but eventually I settled with implementing all the methods in the main FUSE class because the file_class didn't seem to be working for me

Indivisible answered 28/6, 2011 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.