mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
appv2: add support for subdirs property in data_dir
This commit is contained in:
parent
306c5e0e10
commit
4b46f32201
1 changed files with 14 additions and 1 deletions
|
@ -881,13 +881,15 @@ class DatadirAppResource(AppResource):
|
||||||
|
|
||||||
##### Properties
|
##### Properties
|
||||||
- `dir`: (default: `/home/yunohost.app/__APP__`) The full path of the data dir
|
- `dir`: (default: `/home/yunohost.app/__APP__`) The full path of the data dir
|
||||||
|
- `subdirs`: (default: empty list) A list of subdirs to initialize inside the data dir. For example, `['foo', 'bar']`
|
||||||
- `owner`: (default: `__APP__:rwx`) The owner (and owner permissions) for the data dir
|
- `owner`: (default: `__APP__:rwx`) The owner (and owner permissions) for the data dir
|
||||||
- `group`: (default: `__APP__:rx`) The group (and group permissions) for the data dir
|
- `group`: (default: `__APP__:rx`) The group (and group permissions) for the data dir
|
||||||
|
|
||||||
##### Provision/Update
|
##### Provision/Update
|
||||||
- if the dir path changed and a folder exists at the old location, the folder will be `mv`'ed to the new location
|
- if the dir path changed and a folder exists at the old location, the folder will be `mv`'ed to the new location
|
||||||
- otherwise, creates the directory if it doesn't exists yet
|
- otherwise, creates the directory if it doesn't exists yet
|
||||||
- (re-)apply permissions (only on the folder itself, not recursively)
|
- create each subdir declared and which do not exist already
|
||||||
|
- (re-)apply permissions (only on the folder itself and declared subdirs, not recursively)
|
||||||
- save the value of `dir` as `data_dir` in the app's settings, which can be then used by the app scripts (`$data_dir`) and conf templates (`__DATA_DIR__`)
|
- save the value of `dir` as `data_dir` in the app's settings, which can be then used by the app scripts (`$data_dir`) and conf templates (`__DATA_DIR__`)
|
||||||
|
|
||||||
##### Deprovision
|
##### Deprovision
|
||||||
|
@ -910,11 +912,13 @@ class DatadirAppResource(AppResource):
|
||||||
|
|
||||||
default_properties: Dict[str, Any] = {
|
default_properties: Dict[str, Any] = {
|
||||||
"dir": "/home/yunohost.app/__APP__",
|
"dir": "/home/yunohost.app/__APP__",
|
||||||
|
"subdirs": [],
|
||||||
"owner": "__APP__:rwx",
|
"owner": "__APP__:rwx",
|
||||||
"group": "__APP__:rx",
|
"group": "__APP__:rx",
|
||||||
}
|
}
|
||||||
|
|
||||||
dir: str = ""
|
dir: str = ""
|
||||||
|
subdirs: list = []
|
||||||
owner: str = ""
|
owner: str = ""
|
||||||
group: str = ""
|
group: str = ""
|
||||||
|
|
||||||
|
@ -938,6 +942,11 @@ class DatadirAppResource(AppResource):
|
||||||
else:
|
else:
|
||||||
mkdir(self.dir)
|
mkdir(self.dir)
|
||||||
|
|
||||||
|
for subdir in self.subdirs:
|
||||||
|
full_path = os.path.join(self.dir, subdir)
|
||||||
|
if not os.path.isdir(full_path):
|
||||||
|
mkdir(full_path)
|
||||||
|
|
||||||
owner, owner_perm = self.owner.split(":")
|
owner, owner_perm = self.owner.split(":")
|
||||||
group, group_perm = self.group.split(":")
|
group, group_perm = self.group.split(":")
|
||||||
owner_perm_octal = (
|
owner_perm_octal = (
|
||||||
|
@ -956,6 +965,10 @@ class DatadirAppResource(AppResource):
|
||||||
# in which case we want to apply the perm to the pointed dir, not to the symlink
|
# in which case we want to apply the perm to the pointed dir, not to the symlink
|
||||||
chmod(os.path.realpath(self.dir), perm_octal)
|
chmod(os.path.realpath(self.dir), perm_octal)
|
||||||
chown(os.path.realpath(self.dir), owner, group)
|
chown(os.path.realpath(self.dir), owner, group)
|
||||||
|
for subdir in self.subdirs:
|
||||||
|
full_path = os.path.join(self.dir, subdir)
|
||||||
|
chmod(os.path.realpath(full_path), perm_octal)
|
||||||
|
chown(os.path.realpath(full_path), owner, group)
|
||||||
|
|
||||||
self.set_setting("data_dir", self.dir)
|
self.set_setting("data_dir", self.dir)
|
||||||
self.delete_setting("datadir") # Legacy
|
self.delete_setting("datadir") # Legacy
|
||||||
|
|
Loading…
Add table
Reference in a new issue