Make the PathInfo returned by get_pathinfo for a nonexistent path use "now" for ctime...
authorDaira Hopwood <daira@jacaranda.org>
Wed, 30 Sep 2015 15:08:01 +0000 (16:08 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Wed, 30 Sep 2015 15:29:15 +0000 (16:29 +0100)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/test/test_util.py
src/allmydata/util/fileutil.py

index d205309cddb5c4d9f64f72e52a8306e963d7a245..4b7354e9b87102d4108ee5101ad52f392930dba9 100644 (file)
@@ -648,7 +648,7 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
         self.failUnlessFalse(dirinfo.islink)
 
         # create a file under the directory
-        f = os.path.join(basedir, "a/1.txt")
+        f = os.path.join(basedir, "a", "1.txt")
         self.touch(basedir, "a/1.txt", data="a"*10)
         fileinfo = fileutil.get_pathinfo(f)
         self.failUnlessTrue(fileinfo.isfile)
@@ -658,7 +658,7 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
         self.failUnlessEqual(fileinfo.size, 10)
 
         # create a symlink under the directory a pointing to 1.txt
-        slname = os.path.join(basedir, "a/linkto1.txt")
+        slname = os.path.join(basedir, "a", "linkto1.txt")
         os.symlink(f, slname)
         symlinkinfo = fileutil.get_pathinfo(slname)
         self.failUnlessTrue(symlinkinfo.islink)
@@ -666,6 +666,18 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
         self.failUnlessFalse(symlinkinfo.isfile)
         self.failUnlessFalse(symlinkinfo.isdir)
 
+        # path at which nothing exists
+        dnename = os.path.join(basedir, "a", "doesnotexist")
+        now = time.time()
+        dneinfo = fileutil.get_pathinfo(dnename, now=now)
+        self.failUnlessFalse(dneinfo.exists)
+        self.failUnlessFalse(dneinfo.isfile)
+        self.failUnlessFalse(dneinfo.isdir)
+        self.failUnlessFalse(dneinfo.islink)
+        self.failUnlessEqual(dneinfo.size, None)
+        self.failUnlessEqual(dneinfo.mtime, now)
+        self.failUnlessEqual(dneinfo.ctime, now)
+
 
 class PollMixinTests(unittest.TestCase):
     def setUp(self):
index d1e3d6162b6a84203510d68c4897a4c30318cb54..8194fcd4dc68c463c472cb687833a7ccea556945 100644 (file)
@@ -631,7 +631,7 @@ else:
 
 PathInfo = namedtuple('PathInfo', 'isdir isfile islink exists size mtime ctime')
 
-def get_pathinfo(path_u):
+def get_pathinfo(path_u, now=None):
     try:
         statinfo = os.lstat(path_u)
         mode = statinfo.st_mode
@@ -645,12 +645,14 @@ def get_pathinfo(path_u):
                        )
     except OSError as e:
         if e.errno == ENOENT:
+            if now is None:
+                now = time.time()
             return PathInfo(isdir =False,
                             isfile=False,
                             islink=False,
                             exists=False,
                             size  =None,
-                            mtime =None,
-                            ctime =None,
+                            mtime =now,
+                            ctime =now,
                            )
         raise