Skip to content

Commit

Permalink
Rework download logic (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaruni96 authored Aug 9, 2024
1 parent 4f0a91f commit 523a1ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe

### Changed
- Improved logic for uninstall
- Bugfix: interruptible downloads

### Removed

Expand Down
38 changes: 21 additions & 17 deletions src/maps
Original file line number Diff line number Diff line change
Expand Up @@ -449,36 +449,40 @@ def mode_deploy(repo, args):
else:
print("Error: runtime not found! Use list mode --list to view available runtimes.")
sys.exit(1)

DATADIR = f"{os.getenv('HOME')}/.var/org.mardi.maps/{args.DEPLOY}"
PDATADIR = '/'.join(DATADIR.split('/')[0:-1])
if VERBOSE:
print("Setting up direcotires...")
opts1 = '-pv'
opts2 = '-v'
opts3 = ''
else:
opts1 = '-p'
opts2 = ''
opts3 = '2>/dev/null'
subprocess.run(f"mkdir {opts1} {PDATADIR}".split(), check=True)
ret = subprocess.run(f"mkdir {opts2} {DATADIR} {opts3}", shell=True, check=False)
subprocess.run(f"mkdir {opts1} {DATADIR}/rwfs".split(), check=True)
subprocess.run(f"mkdir {opts1} {DATADIR}/tmpfs".split(), check=True)
subprocess.run(f"mkdir {opts1} {DATADIR}/live".split(), check=True)
if ret.returncode != 0:

# check if update
if os.path.exists(DATADIR):
print("Directory already exists, trying to update...")
ret = mode_update(repo, args)
if ret == 1:
raise AssertionError("Error: Unknown error!")
if ret == 2:
print(f"{args.DEPLOY} already installed and up to date.... nothing to do!")
return

# download
for remote in repo.remote_list():
if args.DEPLOY in repo.remote_list_refs(remote)[1]:
refhash = repo.remote_list_refs(remote)[1][args.DEPLOY]
if VERBOSE:
print(f"Downloading {refhash}...")
download(args, repo, remote, args.DEPLOY)
break

# setup directories
if VERBOSE:
print("Setting up direcotires...")
opts1 = '-pv'
else:
opts1 = '-p'
subprocess.run(f"mkdir {opts1} {PDATADIR}".split(), check=True)
subprocess.run(f"mkdir {opts1} {DATADIR}", shell=True, check=True)
subprocess.run(f"mkdir {opts1} {DATADIR}/rwfs".split(), check=True)
subprocess.run(f"mkdir {opts1} {DATADIR}/tmpfs".split(), check=True)
subprocess.run(f"mkdir {opts1} {DATADIR}/live".split(), check=True)

# checkout from local repo
tfd = os.open(DATADIR, os.O_RDONLY)
osopts = blank_options()
osopts.bareuseronly_dirs = True
Expand Down

0 comments on commit 523a1ab

Please sign in to comment.