Block in file fixes

This commit is contained in:
Olivier 'reivilibre' 2021-06-17 20:41:56 +01:00
parent e6df07e744
commit f83c624b08
2 changed files with 5 additions and 15 deletions

View File

@ -402,10 +402,8 @@ class FridgeBlockInFile(Recipe):
self._desugared_src = desugared_src
self.marker_line_prefix = check_type_opt(
args.get("marker_line_prefix", "# "), str
)
self.marker_name = check_type_opt(args.get("marker_name"), str)
self.marker_line_prefix = check_type(args.get("marker_line_prefix", "# "), str)
self.marker_name = check_type(args.get("marker_name"), str)
def prepare(self, preparation: Preparation, head: Head) -> None:
super().prepare(preparation, head)
@ -423,7 +421,7 @@ class FridgeBlockInFile(Recipe):
k, self.fridge_meta, self.real_path, self.recipe_context.variables
)
dest_str = str(self.destination)
chan = await k.ut0(
await k.ut0(
WriteBlockInFile(
dest_str,
self.mode,
@ -432,14 +430,8 @@ class FridgeBlockInFile(Recipe):
data.decode(),
)
)
if await chan.recv() != "OK":
raise RuntimeError(f"WriteBlockInFile failed to {self.destination}")
if self.targ_user or self.targ_group:
await k.ut0(Chown(dest_str, self.targ_user, self.targ_group))
# this is the wrong thing
# hash_of_data = sha256_bytes(data)
# k.get_dependency_tracker().register_remote_file(dest_str, hash_of_data)
k.get_dependency_tracker().register_fridge_file(self._desugared_src)

View File

@ -72,12 +72,12 @@ class WriteBlockInFile(Utensil):
start_index = file_lines.index(start_marker)
end_index = file_lines.index(end_marker)
file_lines = file_lines[:start_index] + file_lines[end_index + 1 :]
except IndexError:
except ValueError:
pass
else:
file_lines = []
file_lines.append(start_marker + self.data + end_marker)
file_lines.append(start_marker + self.data + "\n" + end_marker)
oldumask = os.umask(0)
fdnum = os.open(self.path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, self.mode)
@ -86,8 +86,6 @@ class WriteBlockInFile(Utensil):
with open(fdnum, "w") as file:
file.writelines(file_lines)
await channel.send("OK")
@attr.s(auto_attribs=True)
class MakeDirectory(Utensil):