Skip to content

Commit

Permalink
improved deleting of CM entries on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
gfursin authored and pgmpablo157321 committed Mar 25, 2024
1 parent 8f6f8fe commit 2a08528
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
1 change: 1 addition & 0 deletions cm/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- added skip of delayed help to simplify output of `cmr [tags] --help`
- revisited automatically generated READMEs for CM scripts (automation recipes)
based on user feedback: https://github.com/mlcommons/ck/issues/1169
- improved deleting of CM entries on Windows

## V2.0.3
- added support to handle broken CM repositories: https://github.com/mlcommons/ck/issues/1177
Expand Down
27 changes: 14 additions & 13 deletions cm/cmind/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,8 @@ def delete(self, i):

if os.name == 'nt':
# To be able to remove .git files
shutil.rmtree(path_to_artifact, ignore_errors = False, onerror = delete_helper)
shutil.rmtree(path_to_artifact, onerror = utils.rm_read_only)
# shutil.rmtree(path_to_artifact, ignore_errors = False, onerror = delete_helper)
else:
shutil.rmtree(path_to_artifact)

Expand Down Expand Up @@ -1254,15 +1255,15 @@ def info(self, i):

return {'return':0, 'list': lst}

############################################################
def delete_helper(func, path, ret):
import stat, errno

if ret[1].errno != errno.EACCES:
raise
else:
clean_attr = stat.S_IRWXG | stat.S_IRWXO | stat.S_IRWXU
os.chmod(path, clean_attr)
func(path)

return
#############################################################
#def delete_helper(func, path, ret):
# import stat, errno
#
# if ret[1].errno != errno.EACCES:
# raise
# else:
# clean_attr = stat.S_IRWXG | stat.S_IRWXO | stat.S_IRWXU
# os.chmod(path, clean_attr)
# func(path)
#
# return
22 changes: 2 additions & 20 deletions cm/cmind/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def pull(self, alias, url = '', branch = '', checkout = '', console = False, des

print ('')
print ('Deleting {} ...'.format(path_to_repo))
shutil.rmtree(path_to_repo, onerror=rm_read_only)
shutil.rmtree(path_to_repo, onerror=utils.rm_read_only)
print ('')

cur_dir = os.getcwd()
Expand Down Expand Up @@ -654,27 +654,9 @@ def delete(self, lst, remove_all = False, console = False, force = False):
if console:
print (' Deleting repository content ...')

shutil.rmtree(path_to_repo, onerror=rm_read_only)
shutil.rmtree(path_to_repo, onerror=utils.rm_read_only)
else:
if console:
print (' CM repository was unregistered from CM but its content was not deleted ...')

return {'return':0}

##############################################################################
def rm_read_only(f, p, e):
"""
Internal aux function to remove files and dirs even if read only
particularly on Windows
"""

import os
import stat
import errno

ex = e[1]

os.chmod(p, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
f(p)

return
18 changes: 18 additions & 0 deletions cm/cmind/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,3 +1613,21 @@ def tags_matched(tags, and_tags, no_tags):
break

return matched

##############################################################################
def rm_read_only(f, p, e):
"""
Internal aux function to remove files and dirs even if read only
particularly on Windows
"""

import os
import stat
import errno

ex = e[1]

os.chmod(p, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
f(p)

return

0 comments on commit 2a08528

Please sign in to comment.