glenn-jocher commited on
Commit
22ee6fb
·
unverified ·
1 Parent(s): ff35292

Update `is_writeable()` for 2 methods (#4744)

Browse files

* Writeable test

* Fix

* Cleanup

Files changed (1) hide show
  1. utils/general.py +13 -11
utils/general.py CHANGED
@@ -112,17 +112,19 @@ def user_config_dir(dir='Ultralytics'):
112
  return path
113
 
114
 
115
- def is_writeable(dir):
116
- # Return True if directory has write permissions
117
- # return os.access(path, os.R_OK) # known issue on Windows
118
- file = Path(dir) / 'tmp.txt'
119
- try:
120
- with open(file, 'w'):
121
- pass
122
- file.unlink() # remove file
123
- return True
124
- except IOError:
125
- return False
 
 
126
 
127
 
128
  def is_docker():
 
112
  return path
113
 
114
 
115
+ def is_writeable(dir, test=False):
116
+ # Return True if directory has write permissions, test opening a file with write permissions if test=True
117
+ if test: # method 1
118
+ file = Path(dir) / 'tmp.txt'
119
+ try:
120
+ with open(file, 'w'): # open file with write permissions
121
+ pass
122
+ file.unlink() # remove file
123
+ return True
124
+ except IOError:
125
+ return False
126
+ else: # method 2
127
+ return os.access(dir, os.R_OK) # possible issues on Windows
128
 
129
 
130
  def is_docker():