Zim

Atomic replace fails on mounted file system

Bug #1364980 reported by Sander Maijers
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zim
Confirmed
Low
Unassigned

Bug Description

Saving a page of a Zim (0.61) notebook to an SSHFS FUSE mount on Linux of a Windows SSH (SFTP) server fails in the method zim.fs.UnixFile#_on_write as an OSError is raised from:
  os.rename(tmp, self.encodedpath)

The comment:
# On Unix, for rename() if dest already exists it is replaced in an
# atomic operation. And other processes reading our file will not
# block moving it :)
seems not to hold true in this case.

A straightforward patch is to replace said line with:
  try:
   os.rename(tmp, self.encodedpath)
  except OSError:
   if os.path.exists(self.encodedpath):
    os.unlink(self.encodedpath)
    os.rename(tmp, self.encodedpath)

This is not a particularly robust solution because the exception raised is rather broad (OSError) and because further exceptions raised are not handled in this code. Finer-grained IO exception classes and a cross-platform atomic file moving function os.replace() are only available in Python 3.3+. See: http://bugs.python.org/issue8828

Tags: filesystem
description: updated
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Probably should add a (hidden) config option to disable replace on such file systems.

summary: - Chrash on writing a page (+patch)
+ Atomic replace fails on mounted file system
Changed in zim:
status: New → Confirmed
importance: Undecided → Low
tags: added: filesystem
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.