Skip to content

Commit 8fb5aa7

Browse files
authored
Merge pull request #82 from shirleylxie/master
Do not raise exception when path already exists
2 parents b89c431 + bbb7b72 commit 8fb5aa7

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/isilon_hadoop_tools/directories.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import logging
77
import posixpath
88

9+
import isilon_hadoop_tools.onefs
910
from isilon_hadoop_tools import IsilonHadoopToolError
1011

11-
1212
__all__ = [
1313
# Exceptions
1414
'DirectoriesError',
@@ -62,7 +62,13 @@ def create_directories(self, directories, setup=None, mkdir=None, chmod=None, ch
6262
for directory in directories:
6363
path = posixpath.join(zone_hdfs, directory.path.lstrip(posixpath.sep))
6464
LOGGER.info("mkdir '%s%s'", zone_root, path)
65-
(mkdir or self.onefs.mkdir)(path, directory.mode, zone=self.onefs_zone)
65+
try:
66+
(mkdir or self.onefs.mkdir)(path, directory.mode, zone=self.onefs_zone)
67+
except isilon_hadoop_tools.onefs.APIError as exc:
68+
if exc.dir_path_already_exists_error():
69+
LOGGER.warning("%s%s already exists. ", zone_root, path)
70+
else:
71+
raise
6672
LOGGER.info("chmod '%o' '%s%s'", directory.mode, zone_root, path)
6773
(chmod or self.onefs.chmod)(path, directory.mode, zone=self.onefs_zone)
6874
LOGGER.info("chown '%s:%s' '%s%s'", directory.owner, directory.group, zone_root, path)

src/isilon_hadoop_tools/onefs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ class APIError(_BaseAPIError):
288288
user_not_found_error_format = "Failed to find user for 'USER:{0}': No such user"
289289
user_unresolvable_error_format = "Could not resolve user {0}"
290290
zone_not_found_error_format = 'Access Zone "{0}" not found.'
291+
dir_path_already_exists_error_format = \
292+
'Unable to create directory as requested -- container already exists'
291293
# pylint: enable=invalid-name
292294

293295
def __str__(self):
@@ -459,6 +461,14 @@ def zone_not_found_error(self, zone_name):
459461
)
460462
)
461463

464+
def dir_path_already_exists_error(self):
465+
"""Returns True if the exception contains a directory path already exist error."""
466+
return any(
467+
self.filtered_errors(
468+
lambda error: error['message'] == self.dir_path_already_exists_error_format,
469+
)
470+
)
471+
462472

463473
class MissingLicenseError(OneFSError):
464474
"""This Exception is raised when a license that is expected to exist cannot be found."""

0 commit comments

Comments
 (0)