From e9f1273fa8ee449c23a8fa4bcaff40b8a37172f0 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 6 Apr 2014 13:49:08 +0200 Subject: [PATCH] Fix case where path exists but is not a dir --- tests/storage/test_filesystem.py | 11 +++++++++-- vdirsyncer/storage/filesystem.py | 10 ++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/storage/test_filesystem.py b/tests/storage/test_filesystem.py index ac8f8ba..62c6d46 100644 --- a/tests/storage/test_filesystem.py +++ b/tests/storage/test_filesystem.py @@ -27,10 +27,17 @@ class TestFilesystemStorage(StorageTests): os.makedirs(os.path.join(path, collection)) return {'path': path, 'fileext': '.txt', 'collection': collection} - def test_create_directory(self, tmpdir): - with pytest.raises(ValueError): + def test_create_is_false(self, tmpdir): + with pytest.raises(IOError): self.storage_class(str(tmpdir), '.txt', collection='lol', create=False) + def test_is_not_directory(self, tmpdir): + with pytest.raises(IOError): + f = tmpdir.join('hue') + f.write('stub') + self.storage_class(str(tmpdir), '.txt', collection='hue') + + def test_create_is_true(self, tmpdir): self.storage_class(str(tmpdir), '.txt', collection='asd') assert tmpdir.listdir() == [tmpdir.join('asd')] diff --git a/vdirsyncer/storage/filesystem.py b/vdirsyncer/storage/filesystem.py index 7e5852b..2d069a8 100644 --- a/vdirsyncer/storage/filesystem.py +++ b/vdirsyncer/storage/filesystem.py @@ -44,13 +44,15 @@ class FilesystemStorage(Storage): if collection is not None: path = os.path.join(path, collection) if not os.path.isdir(path): + if os.path.exists(path): + raise IOError('{} is not a directory.') if create: os.makedirs(path, 0750) else: - raise ValueError('Directory {} does not exist. Use create = ' - 'True in your configuration to automatically ' - 'create it, or create it ' - 'yourself.'.format(path)) + raise IOError('Directory {} does not exist. Use create = ' + 'True in your configuration to automatically ' + 'create it, or create it ' + 'yourself.'.format(path)) self.collection = collection self.path = expand_path(path) self.encoding = encoding