From 38c585a5f91b471501739e8061980c39394dcd1c Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 6 Jun 2018 02:37:51 +0300 Subject: [PATCH] checkout: create dir even if it is empty Fixes #737 Signed-off-by: Ruslan Kuprieiev --- dvc/remote/local.py | 5 +++++ tests/test_checkout.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/dvc/remote/local.py b/dvc/remote/local.py index 75602ae0a..9c98d493a 100644 --- a/dvc/remote/local.py +++ b/dvc/remote/local.py @@ -160,6 +160,11 @@ class RemoteLOCAL(RemoteBase): msg = u'Checking out directory \'{}\' with cache \'{}\'' Logger.debug(msg.format(os.path.relpath(path), os.path.relpath(cache))) + # Create dir separately so that dir is created + # even if there are no files in it + if not os.path.exists(path): + os.makedirs(path) + dir_cache = self.dir_cache(cache) for relpath, c in dir_cache.items(): p = os.path.join(path, relpath) diff --git a/tests/test_checkout.py b/tests/test_checkout.py index f39263ac2..95a0b807b 100644 --- a/tests/test_checkout.py +++ b/tests/test_checkout.py @@ -170,3 +170,20 @@ class TestCheckoutMissingMd5InStageFile(TestRepro): yaml.dump(d, fd) self.dvc.checkout() + + +class TestCheckoutEmptyDir(TestDvc): + def test(self): + dname = 'empty_dir' + os.mkdir(dname) + + stage = self.dvc.add(dname) + self.assertEqual(len(stage.outs), 1) + + stage.outs[0].remove() + self.assertFalse(os.path.exists(dname)) + + self.dvc.checkout() + + self.assertTrue(os.path.isdir(dname)) + self.assertEqual(len(os.listdir(dname)), 0)