Skip to content

Commit

Permalink
Fix receive open mode when img file not present
Browse files Browse the repository at this point in the history
Fix error from chattr

Fix get_lvm_vgs when local volgroup is missing
  • Loading branch information
tasket committed Mar 7, 2023
1 parent e359262 commit 8dade75
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions wyng
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -2941,16 +2948,16 @@ 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"
" --save-to=/dev/volgroup/lv in case of a thin LV.")
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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3732,4 +3739,5 @@ elif options.action == "arch-deduplicate":


cleanup()

# END

0 comments on commit 8dade75

Please sign in to comment.