diff --git a/src/python/cram/v1.py b/src/python/cram/v1.py index eb70efb..e0b7003 100644 --- a/src/python/cram/v1.py +++ b/src/python/cram/v1.py @@ -75,17 +75,25 @@ class PackageV1(Package): sum = sum.hexdigest() installf = self.root / content - if installf.exists(): - with open(installf, "r") as fp: - self.do_sh_or_script(fp.read(), fs, dest) - elif content: + def _installf_exists(): + try: + return installf.exists() + except OSError as e: + return False + + if content.startswith("#!") or "\n" in content or not _installf_exists(): f = tempf(self.global_config, f"{sum}.sh") f.parent.mkdir(exist_ok=True, parents=True) with open(f, "w") as fp: fp.write(content) fs.exec(cwd, sh(self.global_config, [str(f)])) + else: + with open(installf, "r") as fp: + self.do_sh_or_script(fp.read(), fs, dest) + + def do_build(self, fs: Vfs, dest: Path): self.do_sh_or_script(self.config().get("package", {}).get("build"), fs, dest)