Make fridge-copy able to chown files

This commit is contained in:
Olivier 'reivilibre' 2021-01-02 19:24:46 +00:00
parent 7fbf526c8b
commit 846695cfa6
2 changed files with 20 additions and 4 deletions

View File

@ -44,7 +44,7 @@ from scone.default.utensils.basic_utensils import (
from scone.head.head import Head
from scone.head.kitchen import Kitchen, Preparation
from scone.head.recipe import Recipe, RecipeContext
from scone.head.utils import check_type
from scone.head.utils import check_type, check_type_opt
logger = logging.getLogger(__name__)
@ -85,6 +85,9 @@ class FridgeCopy(Recipe):
self.fridge_meta: FridgeMetadata = meta
self.mode = parse_mode(mode, directory=False)
self.targ_user = check_type_opt(args.get("owner"), str)
self.targ_group = check_type_opt(args.get("group"), str)
self._desugared_src = desugared_src
def prepare(self, preparation: Preparation, head: Head) -> None:
@ -92,6 +95,12 @@ class FridgeCopy(Recipe):
preparation.provides("file", str(self.destination))
preparation.needs("directory", str(self.destination.parent))
if self.targ_user:
preparation.needs("os-user", self.targ_user)
if self.targ_group:
preparation.needs("os-group", self.targ_group)
async def cook(self, k: Kitchen) -> None:
data = await load_and_transform(
k, self.fridge_meta, self.real_path, self.recipe_context.variables
@ -103,6 +112,13 @@ class FridgeCopy(Recipe):
if await chan.recv() != "OK":
raise RuntimeError(f"WriteFail failed on fridge-copy 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)

View File

@ -22,7 +22,7 @@ import os
import pwd
import shutil
import stat
from typing import List
from typing import List, Optional
import attr
@ -117,8 +117,8 @@ class Stat(Utensil):
@attr.s(auto_attribs=True)
class Chown(Utensil):
path: str
user: str
group: str
user: Optional[str]
group: Optional[str]
async def execute(self, channel: Channel, worktop):
shutil.chown(self.path, self.user, self.group)