state: account for directories when computing size

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2019-01-15 17:17:15 +02:00
parent ced57a4382
commit 60e9ed4f0b
2 changed files with 6 additions and 12 deletions
+3 -11
View File
@@ -245,26 +245,18 @@ class State(object):
@staticmethod
def mtime_and_size(path):
size = os.path.getsize(path)
mtime = os.path.getmtime(path)
if os.path.isdir(path):
size = 0
for root, dirs, files in os.walk(path):
for dname in dirs:
p = os.path.join(root, dname)
m = os.path.getmtime(p)
if m > mtime:
mtime = m
for fname in files:
p = os.path.join(root, fname)
for name in dirs + files:
p = os.path.join(root, name)
st = os.stat(p)
size += st.st_size
m = st.st_mtime
if m > mtime:
mtime = m
else:
size = os.path.getsize(path)
# State of files handled by dvc is stored in db as TEXT.
# We cast results to string for later comparisons with stored values.
+3 -1
View File
@@ -10,7 +10,9 @@ class TestMtimeAndSize(TestDvc):
dir_time, dir_size = State.mtime_and_size(self.DATA_DIR)
actual_file_size = os.path.getsize(self.DATA)
actual_dir_size = (os.path.getsize(self.DATA)
actual_dir_size = (os.path.getsize(self.DATA_DIR)
+ os.path.getsize(self.DATA)
+ os.path.getsize(self.DATA_SUB_DIR)
+ os.path.getsize(self.DATA_SUB))
self.assertIs(type(file_time), str)