Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes: python3, s3 paths with subfolders #178

Merged
merged 6 commits into from
Oct 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make sure dirname is a string before replacing the cache_path in remo…
…ve_empty_dirs
  • Loading branch information
Becky Smith committed Oct 9, 2018
commit 973976420dbcf23f630fc7fb0744d0475eae0b44
12 changes: 7 additions & 5 deletions yas3fs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3111,25 +3111,27 @@ def remove_empty_dirs(dirname):
logger.debug("remove_empty_dirs '%s'" % (dirname))

try:
if not isinstance(dirname, bytes):
dirname = dirname.encode('utf-8')
if not isinstance(dirname, str):
# dirname must be a string for replace
dirname = dirname.decode('utf-8')

# fix for https://github.com/danilop/yas3fs/issues/150
# remove cache_path part from dirname to avoid accidental removal of /tmp (if empty)
os.chdir(yas3fsobj.cache_path)
dirname = dirname.replace(yas3fsobj.cache_path + '/', '')

dirname = dirname.encode('utf-8')
os.removedirs(dirname)
logger.debug("remove_empty_dirs '%s' done" % (dirname))
logger.debug("remove_empty_dirs '%s' done", dirname)
except OSError as exc: # Python >2.5
if exc.errno == errno.ENOTEMPTY:
logger.debug("remove_empty_dirs '%s' not empty" % (dirname))
logger.debug("remove_empty_dirs '%s' not empty", dirname)
pass
else:
raise
except Exception as e:
logger.exception(e)
logger.error("remove_empty_dirs exception: " + dirname)
logger.error("remove_empty_dirs exception: %s", dirname)
raise e


Expand Down