Skip to content

Commit 70d15c6

Browse files
committed
Address a few corner case bugs in the check access and get file size helpers of
the `fileio.py` module as explained in issue #378 and covered by the unit tests in PR #377.
1 parent 6e3df14 commit 70d15c6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

mig/shared/fileio.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def _write_chunk(path, chunk, offset, logger=None, mode='r+b',
150150
return False
151151

152152
# TODO: toggle default force_string here when we have auto mode select?
153+
154+
153155
def write_chunk(path, chunk, offset, logger, mode='r+b', force_string=True):
154156
"""Wrapper to handle writing of chunks with offset to path.
155157
Creates file first if it doesn't already exist.
@@ -176,7 +178,7 @@ def write_file(content, path, logger, mode='w', make_parent=True, umask=None,
176178
old_umask = os.umask(umask)
177179

178180
# TODO: enable this again once throuroughly tested and assured py2+3 safe
179-
#mode = _auto_adjust_mode(content, mode)
181+
# mode = _auto_adjust_mode(content, mode)
180182

181183
retval = _write_chunk(path, content, offset=0, logger=logger, mode=mode,
182184
make_parent=make_parent, create_file=False,
@@ -311,7 +313,7 @@ def get_file_size(path, logger):
311313
return os.path.getsize(path)
312314
except Exception as err:
313315
logger.error("could not get size for %r: %s" % (path, err))
314-
result = -1
316+
return -1
315317

316318

317319
def delete_file(path, logger, allow_broken_symlink=False, allow_missing=False):
@@ -752,7 +754,7 @@ def check_read_access(path, parent_dir=False, follow_symlink=True):
752754
argument decides if any symlinks in path are expanded before this check
753755
and it is on by default.
754756
"""
755-
return _check_access(path, os.O_RDONLY, parent_dir, follow_symlink)
757+
return _check_access(path, os.R_OK, parent_dir, follow_symlink)
756758

757759

758760
def check_write_access(path, parent_dir=False, follow_symlink=True):
@@ -762,8 +764,7 @@ def check_write_access(path, parent_dir=False, follow_symlink=True):
762764
decides if any symlinks in path are expanded before this check and it is
763765
on by default.
764766
"""
765-
# IMPORTANT: we need to use RDWR rather than WRONLY here.
766-
return _check_access(path, os.O_RDWR, parent_dir, follow_symlink)
767+
return _check_access(path, os.W_OK, parent_dir, follow_symlink)
767768

768769

769770
def make_temp_file(suffix='', prefix='tmp', dir=None, text=False):

0 commit comments

Comments
 (0)