Question

I'm using memory.py from fusepy (http://code.google.com/p/fusepy/source/browse/trunk/memory.py) for a programming assignment.

How does setxattr (line 87) actually accomplish anything? self.files isn't modified in any way and attrs is destroyed when the function exits.

Was it helpful?

Solution

def setxattr(self, path, name, value, options, position=0):
    # Ignore options
    attrs = self.files[path].setdefault('attrs', {})
    attrs[name] = value

The side-effect is achieved by setdefault, which creates a new item in self.files[path] (unless attrs already exists as a key in it), and returns a reference to the value.

Next, that reference is modified, by assigning to its key name, the value value. By that operation too, self.files is modified.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top