Skip to content

Commit bc6033b

Browse files
author
dzsekijo
committed
Fix flush and fsync in xmp.py.
- Don't call file.flush() if file is not open for writing (a fix for OS-es which adhere more to POSIX than Linux in this respect, eg. *BSD). - Do call file.flush() both from both of fsync and flush methods because data is to be flushed out from userspace cache anyway before we can go on.
1 parent a32dc39 commit bc6033b

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

example/xmp.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,19 @@ def write(self, buf, offset):
180180
def release(self, flags):
181181
self.file.close()
182182

183+
def _fflush(self):
184+
if 'w' in self.file.mode or 'a' in self.file.mode:
185+
self.file.flush()
186+
183187
def fsync(self, isfsyncfile):
188+
self._fflush()
184189
if isfsyncfile and hasattr(os, 'fdatasync'):
185190
os.fdatasync(self.fd)
186191
else:
187192
os.fsync(self.fd)
188193

189194
def flush(self):
190-
self.file.flush()
195+
self._fflush()
191196
# cf. xmp_flush() in fusexmp_fh.c
192197
os.close(os.dup(self.fd))
193198

0 commit comments

Comments
 (0)