mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
app resource: handle the --purge logic for data_dir removal
This commit is contained in:
parent
a50e73dc0f
commit
8ab28849a1
2 changed files with 22 additions and 14 deletions
|
@ -1282,7 +1282,7 @@ def app_remove(operation_logger, app, purge=False):
|
||||||
from yunohost.utils.resources import AppResourceManager
|
from yunohost.utils.resources import AppResourceManager
|
||||||
|
|
||||||
AppResourceManager(app, wanted={}, current=manifest).apply(
|
AppResourceManager(app, wanted={}, current=manifest).apply(
|
||||||
rollback_and_raise_exception_if_failure=False
|
rollback_and_raise_exception_if_failure=False, purge_data_dir=purge
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Remove all permission in LDAP
|
# Remove all permission in LDAP
|
||||||
|
|
|
@ -536,6 +536,8 @@ class InstalldirAppResource(AppResource):
|
||||||
if not current_install_dir and os.path.isdir(self.dir):
|
if not current_install_dir and os.path.isdir(self.dir):
|
||||||
rm(self.dir, recursive=True)
|
rm(self.dir, recursive=True)
|
||||||
|
|
||||||
|
# isdir will be True if the path is a symlink pointing to a dir
|
||||||
|
# This should cover cases where people moved the data dir to another place via a symlink (ie we dont enter the if)
|
||||||
if not os.path.isdir(self.dir):
|
if not os.path.isdir(self.dir):
|
||||||
# Handle case where install location changed, in which case we shall move the existing install dir
|
# Handle case where install location changed, in which case we shall move the existing install dir
|
||||||
# FIXME: confirm that's what we wanna do
|
# FIXME: confirm that's what we wanna do
|
||||||
|
@ -564,8 +566,10 @@ class InstalldirAppResource(AppResource):
|
||||||
|
|
||||||
perm_octal = 0o100 * owner_perm_octal + 0o010 * group_perm_octal
|
perm_octal = 0o100 * owner_perm_octal + 0o010 * group_perm_octal
|
||||||
|
|
||||||
chmod(self.dir, perm_octal)
|
# NB: we use realpath here to cover cases where self.dir could actually be a symlink
|
||||||
chown(self.dir, owner, group)
|
# 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)
|
||||||
|
chown(os.path.realpath(self.dir), owner, group)
|
||||||
# FIXME: shall we apply permissions recursively ?
|
# FIXME: shall we apply permissions recursively ?
|
||||||
|
|
||||||
self.set_setting("install_dir", self.dir)
|
self.set_setting("install_dir", self.dir)
|
||||||
|
@ -605,9 +609,8 @@ class DatadirAppResource(AppResource):
|
||||||
- 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:
|
||||||
- recursively deletes the directory if it exists
|
- (only if the purge option is chosen by the user) recursively deletes the directory if it exists
|
||||||
- FIXME: this should only be done if the PURGE option is set
|
- also delete the corresponding setting
|
||||||
- FIXME: this should also delete the corresponding setting
|
|
||||||
|
|
||||||
##### Legacy management:
|
##### Legacy management:
|
||||||
- In the past, the setting may have been called `datadir`. The code will automatically rename it as `data_dir`.
|
- In the past, the setting may have been called `datadir`. The code will automatically rename it as `data_dir`.
|
||||||
|
@ -641,11 +644,15 @@ class DatadirAppResource(AppResource):
|
||||||
|
|
||||||
current_data_dir = self.get_setting("data_dir") or self.get_setting("datadir")
|
current_data_dir = self.get_setting("data_dir") or self.get_setting("datadir")
|
||||||
|
|
||||||
|
# isdir will be True if the path is a symlink pointing to a dir
|
||||||
|
# This should cover cases where people moved the data dir to another place via a symlink (ie we dont enter the if)
|
||||||
if not os.path.isdir(self.dir):
|
if not os.path.isdir(self.dir):
|
||||||
# Handle case where install location changed, in which case we shall move the existing install dir
|
# Handle case where install location changed, in which case we shall move the existing install dir
|
||||||
# FIXME: same as install_dir, is this what we want ?
|
# FIXME: same as install_dir, is this what we want ?
|
||||||
# FIXME: What if people manually mved the data dir and changed the setting value and dont want the folder to be moved ? x_x
|
|
||||||
if current_data_dir and os.path.isdir(current_data_dir):
|
if current_data_dir and os.path.isdir(current_data_dir):
|
||||||
|
logger.warning(
|
||||||
|
f"Moving {current_data_dir} to {self.dir} ... (this may take a while)"
|
||||||
|
)
|
||||||
shutil.move(current_data_dir, self.dir)
|
shutil.move(current_data_dir, self.dir)
|
||||||
else:
|
else:
|
||||||
mkdir(self.dir)
|
mkdir(self.dir)
|
||||||
|
@ -664,8 +671,10 @@ class DatadirAppResource(AppResource):
|
||||||
)
|
)
|
||||||
perm_octal = 0o100 * owner_perm_octal + 0o010 * group_perm_octal
|
perm_octal = 0o100 * owner_perm_octal + 0o010 * group_perm_octal
|
||||||
|
|
||||||
chmod(self.dir, perm_octal)
|
# NB: we use realpath here to cover cases where self.dir could actually be a symlink
|
||||||
chown(self.dir, owner, group)
|
# 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)
|
||||||
|
chown(os.path.realpath(self.dir), 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
|
||||||
|
@ -676,11 +685,10 @@ class DatadirAppResource(AppResource):
|
||||||
assert self.owner.strip()
|
assert self.owner.strip()
|
||||||
assert self.group.strip()
|
assert self.group.strip()
|
||||||
|
|
||||||
# FIXME: This should rm the datadir only if purge is enabled
|
if context.get("purge_data_dir", False) and os.path.isdir(self.dir):
|
||||||
pass
|
rm(self.dir, recursive=True)
|
||||||
# if os.path.isdir(self.dir):
|
|
||||||
# rm(self.dir, recursive=True)
|
self.delete_setting("data_dir")
|
||||||
# FIXME : in fact we should delete settings to be consistent
|
|
||||||
|
|
||||||
|
|
||||||
class AptDependenciesAppResource(AppResource):
|
class AptDependenciesAppResource(AppResource):
|
||||||
|
|
Loading…
Add table
Reference in a new issue