Skip to content

Commit

Permalink
Update is_writeable() for 2 methods (ultralytics#4744)
Browse files Browse the repository at this point in the history
* Writeable test

* Fix

* Cleanup
  • Loading branch information
glenn-jocher authored Sep 10, 2021
1 parent c4ee655 commit cd01dce
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,19 @@ def user_config_dir(dir='Ultralytics'):
return path


def is_writeable(dir):
# Return True if directory has write permissions
# return os.access(path, os.R_OK) # known issue on Windows
file = Path(dir) / 'tmp.txt'
try:
with open(file, 'w'):
pass
file.unlink() # remove file
return True
except IOError:
return False
def is_writeable(dir, test=False):
# Return True if directory has write permissions, test opening a file with write permissions if test=True
if test: # method 1
file = Path(dir) / 'tmp.txt'
try:
with open(file, 'w'): # open file with write permissions
pass
file.unlink() # remove file
return True
except IOError:
return False
else: # method 2
return os.access(dir, os.R_OK) # possible issues on Windows


def is_docker():
Expand Down

0 comments on commit cd01dce

Please sign in to comment.