|
12 | 12 | fromastimportliteral_eval |
13 | 13 | fromconfigparserimportConfigParser,NoOptionError,NoSectionError |
14 | 14 | fromfilecmpimportcmp |
| 15 | +fromglobimportglob |
15 | 16 | fromreimportsub |
16 | 17 | fromshutilimportcopy,rmtree |
17 | 18 | fromtempfileimportTemporaryDirectory |
18 | 19 | fromurllib.errorimportURLError,HTTPError |
19 | 20 | fromurllib.requestimporturlopen |
| 21 | +try: |
| 22 | +fromsrc.distros._emptyimport* |
| 23 | +exceptImportError: |
| 24 | +pass# ignore |
20 | 25 |
|
21 | 26 | # Directories |
22 | 27 | # All snapshots share one /var |
@@ -60,25 +65,25 @@ def ash_mounts(i, CHR=""): |
60 | 65 | os.system(f"mount --bind --make-slave /etc /.snapshots/rootfs/snapshot-{CHR}{i}/etc{DEBUG}") |
61 | 66 | os.system(f"mount --bind --make-slave /home /.snapshots/rootfs/snapshot-{CHR}{i}/home{DEBUG}") |
62 | 67 | os.system(f"mount --types proc /proc /.snapshots/rootfs/snapshot-{CHR}{i}/proc{DEBUG}") |
63 | | -#os.system(f"mount --rbind --make-rslave /proc /.snapshots/rootfs/snapshot-{CHR}{i}/proc{DEBUG}") ### REVIEW2023 USE THIS INSTEAD? |
64 | | -#os.system(f"mount --bind --make-slave /root /.snapshots/rootfs/snapshot-{CHR}{i}/root{DEBUG}") ### REVIEW2023 ADD THIS TOO? |
| 68 | +#os.system(f"mount --rbind --make-rslave /proc /.snapshots/rootfs/snapshot-{CHR}{i}/proc{DEBUG}") # REVIEWuse this instead? |
| 69 | +#os.system(f"mount --bind --make-slave /root /.snapshots/rootfs/snapshot-{CHR}{i}/root{DEBUG}") # REVIEWadd this too? |
65 | 70 | os.system(f"mount --bind --make-slave /run /.snapshots/rootfs/snapshot-{CHR}{i}/run{DEBUG}") |
66 | | -#os.system(f"mount --rbind --make-rslave /run /.snapshots/rootfs/snapshot-chr{i}/run{DEBUG}") ### REVIEW2023 USE THIS INSTEAD? |
| 71 | +#os.system(f"mount --rbind --make-rslave /run /.snapshots/rootfs/snapshot-chr{i}/run{DEBUG}") # REVIEWuse this instead? |
67 | 72 | os.system(f"mount --rbind --make-rslave /sys /.snapshots/rootfs/snapshot-{CHR}{i}/sys{DEBUG}") |
68 | 73 | os.system(f"mount --bind --make-slave /tmp /.snapshots/rootfs/snapshot-{CHR}{i}/tmp{DEBUG}") |
69 | | -#os.system(f"mount --rbind --make-rslave /tmp /.snapshots/rootfs/snapshot-{CHR}{i}/tmp{DEBUG}") ### REVIEW2023 USE THIS INSTEAD? |
| 74 | +#os.system(f"mount --rbind --make-rslave /tmp /.snapshots/rootfs/snapshot-{CHR}{i}/tmp{DEBUG}") # REVIEWuse this instead? |
70 | 75 | os.system(f"mount --bind --make-slave /var /.snapshots/rootfs/snapshot-{CHR}{i}/var{DEBUG}") |
71 | 76 | ifis_efi(): |
72 | 77 | os.system(f"mount --rbind --make-rslave /sys/firmware/efi/efivars /.snapshots/rootfs/snapshot-{CHR}{i}/sys/firmware/efi/efivars{DEBUG}") |
73 | | -os.system(f"cp --dereference /etc/resolv.conf /.snapshots/rootfs/snapshot-{CHR}{i}/etc/{DEBUG}")### REVIEWMaybe not needed? |
| 78 | +os.system(f"cp --dereference /etc/resolv.conf /.snapshots/rootfs/snapshot-{CHR}{i}/etc/{DEBUG}")# REVIEWmaybe not needed? |
74 | 79 |
|
75 | | -### Lock ash(no longer needed) REVIEW 2023 |
76 | | -###def ash_lock(): |
77 | | -### os.system("touch /.snapshots/ash/lock-disable") |
| 80 | +# Lock ash# REVIEWno longer needed |
| 81 | +#def ash_lock(): |
| 82 | +# os.system("touch /.snapshots/ash/lock-disable") |
78 | 83 |
|
79 | | -### Unlock ash(no longer needed) REVIEW 2023 |
80 | | -###def ash_unlock(): |
81 | | -### os.system("rm -rf /.snapshots/ash/lock") |
| 84 | +# Unlock ash# REVIEWno longer needed |
| 85 | +#def ash_unlock(): |
| 86 | +# os.system("rm -rf /.snapshots/ash/lock") |
82 | 87 |
|
83 | 88 | # Update ash itself |
84 | 89 | defash_update(dbg): |
@@ -358,7 +363,6 @@ def deploy(snap, secondary=False): |
358 | 363 | ###2023 os.system(f"btrfs sub create /.snapshots/var/var-{tmp} >/dev/null 2>&1") # REVIEW pretty sure not needed |
359 | 364 | os.system(f"mkdir -p /.snapshots/rootfs/snapshot-{tmp}/boot{DEBUG}") |
360 | 365 | os.system(f"mkdir -p /.snapshots/rootfs/snapshot-{tmp}/etc{DEBUG}") |
361 | | -###TODEL os.system(f"rm -rf /.snapshots/rootfs/snapshot-{tmp}/var{DEBUG}") |
362 | 366 | rmrf(f"/.snapshots/rootfs/snapshot-{tmp}/var") |
363 | 367 | os.system(f"cp -r --reflink=auto /.snapshots/boot/boot-{snap}/. /.snapshots/rootfs/snapshot-{tmp}/boot{DEBUG}") |
364 | 368 | os.system(f"cp -r --reflink=auto /.snapshots/etc/etc-{snap}/. /.snapshots/rootfs/snapshot-{tmp}/etc{DEBUG}") |
@@ -713,9 +717,9 @@ def post_transactions(snap): |
713 | 717 | # Some operations were moved below to fix hollow functionality ### IMPORTANT REVIEW 2023 |
714 | 718 | # File operations in snapshot-chr |
715 | 719 | # os.system(f"btrfs sub del /.snapshots/rootfs/snapshot-{snap}{DEBUG}") ### REVIEW # Moved to a few lines below ### GOOD_TO_DELETE_2023 |
716 | | -rmrf(f"/.snapshots/boot/boot-chr{snap}","/*") |
| 720 | +rmrf_star(f"/.snapshots/boot/boot-chr{snap}") |
717 | 721 | os.system(f"cp -r --reflink=auto /.snapshots/rootfs/snapshot-chr{snap}/boot/. /.snapshots/boot/boot-chr{snap}{DEBUG}") |
718 | | -rmrf(f"/.snapshots/etc/etc-chr{snap}","/*") |
| 722 | +rmrf_star(f"/.snapshots/etc/etc-chr{snap}") |
719 | 723 | os.system(f"cp -r --reflink=auto /.snapshots/rootfs/snapshot-chr{snap}/etc/. /.snapshots/etc/etc-chr{snap}{DEBUG}") |
720 | 724 | # Keep package manager's cache after installing packages. This prevents unnecessary downloads for each snapshot when upgrading multiple snapshots |
721 | 725 | cache_copy(snap,"post_transactions") |
@@ -899,19 +903,18 @@ def return_children(tree, id): |
899 | 903 | children.remove(id) |
900 | 904 | returnchildren |
901 | 905 |
|
902 | | -# Pythonic rm -rf (for both deleting just contents and everything) |
903 | | -defrmrf(a_path,contents=""): |
904 | | -ifcontents=="/*":# just delete a_path/* |
905 | | -forroot,dirs,filesinos.walk(a_path): |
906 | | -forfinfiles: |
907 | | -os.unlink(os.path.join(root,f)) |
908 | | -fordindirs: |
909 | | -rmtree(os.path.join(root,d)) |
910 | | -else:# delete everything |
911 | | -ifos.path.isfile(a_path): |
912 | | -os.unlink(a_path) |
913 | | -elifos.path.isdir(a_path): |
914 | | -rmtree(a_path) |
| 906 | +# rm -rf for deleting everything recursively (even top folder) |
| 907 | +defrmrf(*item): |
| 908 | +forfinitem: |
| 909 | +ifos.path.isdir(f): |
| 910 | +rmtree(f) |
| 911 | +else: |
| 912 | +os.unlink(f) |
| 913 | + |
| 914 | +# rm -rf for just deleting contents |
| 915 | +defrmrf_star(a_path): |
| 916 | +files=glob(f"{a_path}/*") |
| 917 | +rmrf(*files) |
915 | 918 |
|
916 | 919 | # Rollback last booted deployment |
917 | 920 | defrollback(): |
@@ -1171,24 +1174,24 @@ def tree_sync(tree, tname, force_offline, live): |
1171 | 1174 | tree_sync_helper("chr",snap_from,snap_to)# Pre-sync |
1172 | 1175 | ifliveandsnap_to==get_current_snapshot():# Live sync |
1173 | 1176 | tree_sync_helper("",snap_from,get_tmp())# Post-sync |
1174 | | -post_transactions(snap_to)### IMPORTANTREVIEW2023 - Moved here from the line immediately after first tree_sync_helper |
| 1177 | +post_transactions(snap_to)#REVIEWimportant - Moved here from the line immediately after first tree_sync_helper |
1175 | 1178 | print(f"Tree{tname} synced.") |
1176 | 1179 |
|
1177 | | -# Sync tree helper function ### REVIEW might need to put it in distribution-specific ashpk.py |
| 1180 | +# Sync tree helper function # REVIEW might need to put it in distribution-specific ashpk.py |
1178 | 1181 | deftree_sync_helper(CHR,s_f,s_t): |
1179 | 1182 | os.system("mkdir -p /.snapshots/tmp-db/local/")### REVIEW Still resembling Arch pacman folder structure! |
1180 | | -rmrf("/.snapshots/tmp-db/local","/*")### REVIEW |
| 1183 | +rmrf_star("/.snapshots/tmp-db/local") |
1181 | 1184 | pkg_list_from=pkg_list(s_f,"") |
1182 | 1185 | pkg_list_to=pkg_list(s_t,CHR) |
1183 | 1186 | # Get packages to be inherited |
1184 | 1187 | pkg_list_from= [jforjinpkg_list_fromifjnotinpkg_list_to] |
1185 | 1188 | os.system(f"cp -r /.snapshots/rootfs/snapshot-{CHR}{s_t}/usr/share/ash/db/local/. /.snapshots/tmp-db/local/")### REVIEW |
1186 | 1189 | os.system(f"cp -n -r --reflink=auto /.snapshots/rootfs/snapshot-{s_f}/. /.snapshots/rootfs/snapshot-{CHR}{s_t}/{DEBUG}") |
1187 | | -rmrf(f"/.snapshots/rootfs/snapshot-{CHR}{s_t}/usr/share/ash/db/local","/*")### REVIEW |
| 1190 | +rmrf_star(f"/.snapshots/rootfs/snapshot-{CHR}{s_t}/usr/share/ash/db/local") |
1188 | 1191 | os.system(f"cp -r /.snapshots/tmp-db/local/. /.snapshots/rootfs/snapshot-{CHR}{s_t}/usr/share/ash/db/local/")### REVIEW |
1189 | 1192 | forentryinpkg_list_from: |
1190 | 1193 | os.system(f"bash -c 'cp -r /.snapshots/rootfs/snapshot-{s_f}/usr/share/ash/db/local/{entry}-[0-9]* /.snapshots/rootfs/snapshot-{CHR}{s_t}/usr/share/ash/db/local/'")### REVIEW |
1191 | | -rmrf("/.snapshots/tmp-db/local","/*") |
| 1194 | +rmrf_star("/.snapshots/tmp-db/local") |
1192 | 1195 |
|
1193 | 1196 | # Recursively run an update in tree |
1194 | 1197 | deftree_upgrade(tree,tname): |
|