Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use fstat() instead of getsize() in FilesystemReader.size.

  • Loading branch information...
commit b13e7d6a7cc87b9435fc138c04c76aad76fc3718 1 parent f169188
Gavin Panella authored
6  tftp/backend.py
... ...
@@ -1,6 +1,7 @@
1 1
 '''
2 2
 @author: shylent
3 3
 '''
  4
+from os import fstat
4 5
 from tftp.errors import Unsupported, FileExists, AccessViolation, FileNotFound
5 6
 from twisted.python.filepath import FilePath, InsecurePath
6 7
 import shutil
@@ -141,7 +142,10 @@ def size(self):
141 142
         @see: L{IReader.size}
142 143
 
143 144
         """
144  
-        return self.file_path.getsize()
  145
+        if self.file_obj.closed:
  146
+            return None
  147
+        else:
  148
+            return fstat(self.file_obj.fileno()).st_size
145 149
 
146 150
     def read(self, size):
147 151
         """
12  tftp/test/test_backend.py
@@ -77,6 +77,18 @@ def test_size(self):
77 77
         r = FilesystemReader(self.temp_dir.child('foo'))
78 78
         self.assertEqual(len(self.test_data), r.size)
79 79
 
  80
+    def test_size_when_reader_finished(self):
  81
+        r = FilesystemReader(self.temp_dir.child('foo'))
  82
+        r.finish()
  83
+        self.assertIsNone(r.size)
  84
+
  85
+    def test_size_when_file_removed(self):
  86
+        # FilesystemReader.size uses fstat() to discover the file's size, so
  87
+        # the absence of the file does not matter.
  88
+        r = FilesystemReader(self.temp_dir.child('foo'))
  89
+        self.existing_file_name.remove()
  90
+        self.assertEqual(len(self.test_data), r.size)
  91
+
80 92
     def test_cancel(self):
81 93
         r = FilesystemReader(self.temp_dir.child('foo'))
82 94
         r.read(3)

0 notes on commit b13e7d6

Please sign in to comment.
Something went wrong with that request. Please try again.