mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
state: don't forget to compute size of an individual file
Fixes #1488 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+4
-1
@@ -245,10 +245,10 @@ class State(object):
|
||||
|
||||
@staticmethod
|
||||
def mtime_and_size(path):
|
||||
size = 0
|
||||
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)
|
||||
@@ -263,6 +263,9 @@ class State(object):
|
||||
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.
|
||||
return str(int(nanotime.timestamp(mtime))), str(size)
|
||||
|
||||
+9
-1
@@ -1,13 +1,21 @@
|
||||
import os
|
||||
|
||||
from dvc.state import State
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
|
||||
class TestMtimeAndSizeReturnType(TestDvc):
|
||||
class TestMtimeAndSize(TestDvc):
|
||||
def test(self):
|
||||
file_time, file_size = State.mtime_and_size(self.DATA)
|
||||
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)
|
||||
+ os.path.getsize(self.DATA_SUB))
|
||||
|
||||
self.assertIs(type(file_time), str)
|
||||
self.assertIs(type(file_size), str)
|
||||
self.assertEqual(file_size, str(actual_file_size))
|
||||
self.assertIs(type(dir_time), str)
|
||||
self.assertIs(type(dir_size), str)
|
||||
self.assertEqual(dir_size, str(actual_dir_size))
|
||||
|
||||
Reference in New Issue
Block a user