Patch to preserve filenames and mtimes in F-spot network sync



Hi,

Here's a patch to datatypes/File.py to preserve filenames and mtimes
in F-spot network sync.

It contains the following changes:

1. _close_file no longer throws away pending renames and mtimes.

2. to_tempfile creates a temporary directory and copies the file
there, with the original filename.

3. force_new_mtime changes mtime of tempfiles as well.

4. __setstate__ initializes _isProxyFile and _proxyFileSize

For me, this makes the F-spot sync preserve filenames and keep the
correct mtime. I haven't tested it with other dataproviders, but I
don't think it will affect anything negatively. Hope it can help!

Best regards,

Olof Sjöbergh
Index: datatypes/File.py
===================================================================
--- datatypes/File.py	(revision 1657)
+++ datatypes/File.py	(working copy)
@@ -56,18 +56,20 @@
 
     def _close_file(self):
         log.debug("Closing file")
-        self.fileInfo = None
-        self.fileExists = False
-        self.triedOpen = False
 
         #check to see if we have applied the rename/mtimes yet
-        if self.get_filename() == self._newFilename:
+        self._get_file_info()
+        if self.fileInfo.name == self._newFilename:
             log.debug("Clearing pending rename")
             self._newFilename = None
-        if self.get_mtime() == self._newMtime:
+        if datetime.datetime.fromtimestamp(self.fileInfo.mtime) == self._newMtime:
             log.debug("Clearing pending mtime")
             self._newMtime = None
 
+        self.fileInfo = None
+        self.fileExists = False
+        self.triedOpen = False
+
     def _xfer_check_global_cancel_flag(self):
         return conduit.GLOBALS.cancelled
 
@@ -186,8 +188,8 @@
         Copies this file to a temporary file in the system tempdir
         @returns: The local file path
         """
-        #Get a temporary file name
-        tempname = tempfile.mkstemp(prefix="conduit")[1]
+        #Create a temporary directory to copy to
+        tempname = tempfile.mkdtemp(prefix="conduit")
         log.debug("Tempfile %s -> %s" % (self.URI, tempname))
         filename = self.get_filename()
         mtime = self.get_mtime()
@@ -198,7 +200,7 @@
         #retain all original information
         self.force_new_filename(filename)
         self.force_new_mtime(mtime)
-        return tempname
+        return self.get_local_uri()
 
     def exists(self):
         self._open_file()
@@ -254,7 +256,7 @@
         """
         Changes the mtime of the file
         """
-        if self._is_tempfile() or self._is_proxyfile():
+        if self._is_proxyfile():
             self._defer_new_mtime(mtime)
         else:
             try:
@@ -529,6 +531,9 @@
         self.fileInfo = None
         self.fileExists = False
         self.triedOpen = False
+
+        self._isProxyFile = False
+        self._proxyFileSize = None
         
         DataType.DataType.__setstate__(self, data)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]