Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve uninstall #15

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe
### Added

### Changed
- Improved logic for uninstall

### Removed

Expand Down
26 changes: 16 additions & 10 deletions src/maps
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,17 @@ def download(args, repo, remote, refname, cerror=0):
def uninstall_runtime(repo, args):
"""Function to remove a runtime from both the local disk checkout, and the local repo"""
# Check if runtime is checked out
FLAG1 = False
FLAG2 = False
DATADIR = f"{os.getenv('HOME')}/.var/org.mardi.maps/{args.UNINSTALL}"
FLAG_DIREXISTS = False
FLAG_REFEXISTS = False
if ':' in args.UNINSTALL:
remote, uninstall = args.UNINSTALL.split(':')
else:
uninstall = args.UNINSTALL
DATADIR = f"{os.getenv('HOME')}/.var/org.mardi.maps/{uninstall}"
if VERBOSE:
print(f"Trying to remove {args.UNINSTALL}...")
print(f"Trying to remove {uninstall}...")
if os.path.isdir(DATADIR):
FLAG1 = True
FLAG_DIREXISTS = True
if VERBOSE:
print("Deleting files...")
opts = '-rvf'
Expand All @@ -363,21 +367,23 @@ def uninstall_runtime(repo, args):
subprocess.run(f"rm {opts} {DATADIR}".split(), check=True)

for runtime in repo.list_refs()[1].keys():
if args.UNINSTALL in runtime:
FLAG2 = True
if uninstall in runtime:
FLAG_REFEXISTS = True
remote = None
if ':' in runtime:
remote, runtime = runtime.split(':')
if VERBOSE:
print("Marking branch for deletion from repo...")
repo.set_ref_immediate(remote, runtime, None, None)
if VERBOSE:
print("Pruning repo...")
repo.prune(OSTree.RepoPruneFlags(2), -1, None)
break

if not (FLAG1 and FLAG2):
print(f"Error, {args.UNINSTALL} isn't deployed and thus cannot be uninstalled!")
if not (FLAG_DIREXISTS and FLAG_REFEXISTS):
print(f"Error, {uninstall} isn't deployed and thus cannot be uninstalled!")
else:
print(f"Uninstalled {args.UNINSTALL} !")
print(f"Uninstalled {uninstall} !")

sys.exit()

Expand Down
Loading