diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-11-26 09:05:12 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-11-26 09:05:12 +0000 |
commit | cf26bd419e46c3e5edeb5f5ebe45936f47c921c6 (patch) | |
tree | 9425d95e0c65379cc13c8ab94f8e4771c08fe2c2 | |
parent | eaab04cb1e4794f2611ba2b2db542eb2705d4849 (diff) | |
download | obnam-cf26bd419e46c3e5edeb5f5ebe45936f47c921c6.tar.gz |
Use split time fields in SFTP
-rw-r--r-- | obnamlib/plugins/sftp_plugin.py | 17 | ||||
-rwxr-xr-x | test-sftpfs | 10 |
2 files changed, 23 insertions, 4 deletions
diff --git a/obnamlib/plugins/sftp_plugin.py b/obnamlib/plugins/sftp_plugin.py index 727299d6..66c2be66 100644 --- a/obnamlib/plugins/sftp_plugin.py +++ b/obnamlib/plugins/sftp_plugin.py @@ -273,8 +273,17 @@ class SftpFS(obnamlib.VirtualFileSystem): # a signed 32-bit value. This limits the range, but allows # timestamps that are negative (before 1970). Once paramiko is # fixed, this code can be removed. - st.st_mtime = self._force_32bit_timestamp(st.st_mtime) - st.st_atime = self._force_32bit_timestamp(st.st_atime) + st.st_mtime_sec = self._force_32bit_timestamp(st.st_mtime) + st.st_atime_sec = self._force_32bit_timestamp(st.st_atime) + + # Within Obnam, we pretend stat results have st_Xtime_sec and + # st_Xtime_nsec, but not st_Xtime. Remove those fields. + del st.st_mtime + del st.st_atime + + # We only get integer timestamps, so set these explicitly to 0. + st.st_mtime_nsec = 0 + st.st_atime_nsec = 0 return st @@ -380,7 +389,7 @@ class SftpFS(obnamlib.VirtualFileSystem): self.sftp.chmod(pathname, mode) @ioerror_to_oserror - def lutimes(self, pathname, atime, mtime): + def lutimes(self, pathname, atime_sec, atime_nsec, mtime_sec, mtime_nsec): # FIXME: This does not work for symlinks! # Sftp does not have a way of doing that. This means if the restore # target is over sftp, symlinks and their targets will have wrong @@ -391,7 +400,7 @@ class SftpFS(obnamlib.VirtualFileSystem): 'against symlinks (warning appears only first ' 'time)') self.lutimes_warned = True - self.sftp.utime(pathname, (atime, mtime)) + self.sftp.utime(pathname, (atime_sec, mtime_sec)) def link(self, existing_path, new_path): raise obnamlib.Error('Cannot hardlink on SFTP. Sorry.') diff --git a/test-sftpfs b/test-sftpfs index c8632ad3..4d7e626b 100755 --- a/test-sftpfs +++ b/test-sftpfs @@ -58,6 +58,16 @@ class SftpTests(unittest.TestCase, obnamlib.VfsTests): def test_mknod_creates_fifo(self): self.assertRaises(NotImplementedError, self.fs.mknod, 'foo', 0) + + # Override method from the VfsTests class. SFTP doesn't do sub-second + # timestamps, so we fix the test here to not set those fields to nonzero. + def test_lutimes_sets_times_correctly(self): + self.fs.mkdir('foo') + self.fs.lutimes('foo', 1, 2*1000, 3, 4*1000) + self.assertEqual(self.fs.lstat('foo').st_atime_sec, 1) + self.assertEqual(self.fs.lstat('foo').st_atime_nsec, 0) + self.assertEqual(self.fs.lstat('foo').st_mtime_sec, 3) + self.assertEqual(self.fs.lstat('foo').st_mtime_nsec, 0) if __name__ == '__main__': |