Skip to content

Commit

Permalink
shutil windows causes errors
Browse files Browse the repository at this point in the history
  • Loading branch information
KorryKatti committed Apr 7, 2024
1 parent c9193de commit ac01abb
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,32 @@ def start_app():
print(f"Error starting the app: {e}")

# Function to uninstall the app
import os
import shutil
import stat

def uninstall_app():
# Define the onerror handler function
def onerror(func, path, exc_info):
"""
Error handler for ``shutil.rmtree``.
If the error is due to an access error (read only file)
it attempts to add write permission and then retries.
If the error is for another reason it re-raises the error.
"""
# Is the error an access error?
if not os.access(path, os.W_OK):
os.chmod(path, stat.S_IWUSR)
func(path)
else:
raise

# Delete the directory corresponding to the app
try:
shutil.rmtree(app_dir)
# Attempt to remove the directory with the onerror handler
shutil.rmtree(app_dir, onerror=onerror)
print("App directory deleted successfully:", app_dir)

# Remove app ID from downloads.txt
Expand All @@ -430,10 +452,11 @@ def uninstall_app():
except Exception as e:
print(f"Error uninstalling the app: {e}")

# Call cherry() with start and uninstall commands
cherry(start_app, uninstall_app)
except Exception as e:
print(f"Error handling app click: {e}")

# Call cherry() with start and uninstall commands
cherry(start_app, uninstall_app)
except Exception as e:
print(f"Error handling app click: {e}")


import webbrowser
Expand Down

0 comments on commit ac01abb

Please sign in to comment.