From 8dade75d6e3865faf87a1d301148697f3d51e637 Mon Sep 17 00:00:00 2001 From: Christopher Laprise Date: Tue, 7 Mar 2023 17:04:15 -0500 Subject: [PATCH] Fix receive open mode when img file not present Fix error from chattr Fix get_lvm_vgs when local volgroup is missing --- wyng | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/wyng b/wyng index 362e388..e1fe538 100755 --- a/wyng +++ b/wyng @@ -321,6 +321,14 @@ class ArchiveSet: assert hmac.compare_digest(digest, self.b64hash(mbuf)) open(destname,"wb").write(self.decompress(mbuf)) + def set_local(self, localpath): + vgp = opts.local.split("/") + if len(vgp) != 2: raise ValueError("Local: 'volgroup/pool' required.") + self.vgname, self.poolname = vgp + if self.vgname not in volgroups \ + or self.poolname not in volgroups[self.vgname][self.poolname]: + print("Warning: {localpath} not present.") + class ArchiveVolume: @@ -474,7 +482,8 @@ class ArchiveVolume: def decode_manifests(self, sesnames, force=False): for ses in (self.sessions[x] for x in sesnames): if ses.path and force: - os.makedirs(ses.path, exist_ok=True) ; do_exec([[CP.chattr, "+c", ses.path]]) + os.makedirs(ses.path, exist_ok=True) + do_exec([[CP.chattr, "+c", ses.path]], check=False) self.decode_one_manifest(ses, force=force) @@ -936,7 +945,7 @@ def get_lvm_vgs(vg_to_lvols=None): volgroups[vgname].lvs[lvname] = lv if lv.pool_lv: volgroups[vgname].poolnames.add(lv.pool_lv) - if vg_to_lvols: l_vols = volgroups[vg_to_lvols].lvs + l_vols = volgroups[vg_to_lvols].lvs if vg_to_lvols in volgroups else {} def lv_exists(vgname, lvname): @@ -1041,13 +1050,10 @@ def clear_array(ar): # Initialize a new ArchiveSet: def arch_init(aset, opts): - if not opts.local or not opts.dest: - x_it(1,"--local and --dest are required together.") + if not opts.local and not opts.from_arch: + x_it(1,"--local is required for init.") - if opts.local: - vgname, poolname = opts.local.split("/") - aset.vgname = vgname - aset.poolname = poolname + if opts.local: aset.set_local(opts.local) if opts.from_arch: return @@ -1199,6 +1205,7 @@ def get_configs(opts): arch_name = "default" load_children = 1 if opts.action in ("arch-delete","delete","add") else 2 + # Get destination dest = Destination(opts.from_arch or opts.dest, opts.dest_name, arch_name) if (opts.action not in local_actions and dest.sys is not None) \ or opts.remap or opts.from_arch: @@ -1252,7 +1259,7 @@ def get_configs_remote(dest, aname, recv_dir): recv_list= [(x+"/volinfo", ArchiveSet.max_volinfosz) for x in new_aset.conf["volumes"].keys()] fetch_file_blobs(recv_list, recv_dir, dest) - do_exec([[CP.chattr, "+c"] + list(new_aset.conf["volumes"].keys())], cwd=recv_dir) + do_exec([[CP.chattr, "+c"] + list(new_aset.conf["volumes"].keys())], cwd=recv_dir, check=False) new_aset = ArchiveSet(aname, os.path.dirname(recv_dir), dest, children=1, allvols=True, prior_auth=new_aset) @@ -2941,7 +2948,7 @@ def receive_volume(vol, select_ses="", save_path="", diff=False, verify_only=0): if exists(save_path) and stat.S_ISBLK(os.stat(save_path).st_mode): if not sparse_write: do_exec([[CP.blkdiscard, save_path]]) - volf = open(save_path, fopenmode:="r+b") + volf = open(save_path, "r+b") elif save_path.startswith("/dev/"): err_out("Cannot create new volume from ambiguous /dev path." " Please create the volume before using 'receive', or specify" @@ -2949,8 +2956,8 @@ def receive_volume(vol, select_ses="", save_path="", diff=False, verify_only=0): return None else: # file save_type = "file" ; punch_hole = low_level_io.file_punch_hole - fopenmode = "r+b" if sparse_write and exists(save_path) else "wb" - volf = open(save_path, fopenmode) ; volf.truncate(volsize) + if not exists(save_path): open(save_path, "wb").close() + volf = open(save_path, "r+b") ; volf.truncate(volsize) elif diff: if not lv_exists(vgname, datavol): @@ -3371,7 +3378,7 @@ def cleanup(): # Constants / Globals prog_name = "wyng" -prog_version = "0.4alpha2" ; prog_date = "20230225" +prog_version = "0.4alpha2" ; prog_date = "20230306" format_version = 3 ; debug = False ; tmpdir = None admin_permission = os.getuid() == 0 aset = dest = None @@ -3732,4 +3739,5 @@ elif options.action == "arch-deduplicate": cleanup() + # END