From 2c5f4265c6ec7976ccbf1cd347225e8786edbd04 Mon Sep 17 00:00:00 2001 From: Philipp Herzog Date: Wed, 27 Nov 2024 16:11:34 +0100 Subject: [PATCH] [FC-42124] make the deploymenttrash trash dir configurable --- ...FC_42124_make_deploymenttrashdir_configurable.md | 1 + src/batou_ext/file.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 CHANGES.d/20241127_160944_ph_FC_42124_make_deploymenttrashdir_configurable.md diff --git a/CHANGES.d/20241127_160944_ph_FC_42124_make_deploymenttrashdir_configurable.md b/CHANGES.d/20241127_160944_ph_FC_42124_make_deploymenttrashdir_configurable.md new file mode 100644 index 0000000..d1add06 --- /dev/null +++ b/CHANGES.d/20241127_160944_ph_FC_42124_make_deploymenttrashdir_configurable.md @@ -0,0 +1 @@ +- make the DeploymentTrash's trash directory configurable and output a potentially helpful message on OSErrors which could indicate that the trash directory and the directory that is being trashed are on different devices diff --git a/src/batou_ext/file.py b/src/batou_ext/file.py index e950ade..895d4f6 100644 --- a/src/batou_ext/file.py +++ b/src/batou_ext/file.py @@ -41,6 +41,7 @@ class SymlinkAndCleanup(batou.component.Component): systemd_read_max_iops = 100 systemd_write_max_iops = 100 + trashdir = None ## DEPRECATED, do not use use_systemd_run_async_cleanup = False @@ -56,6 +57,7 @@ def configure(self): self += DeploymentTrash( read_iops_limit=self.systemd_read_max_iops, write_iops_limit=self.systemd_write_max_iops, + trashdir=self.trashdir, ) self.trash = self._ @@ -166,8 +168,12 @@ class DeploymentTrash(batou.component.Component): read_iops_limit = 100 write_iops_limit = 100 + trashdir = None + def configure(self): - self.trashdir = os.path.expanduser("~/.deployment-trash") + if not self.trashdir: + self.trashdir = os.path.expanduser("~/.deployment-trash") + self += batou.lib.file.File(self.trashdir, ensure="directory") self += batou.lib.file.File( "/etc/local/nixos/trash.nix", @@ -194,3 +200,8 @@ def discard(self, path): except FileNotFoundError: # Nothing to delete. pass + except OSError as e: + batou.output.annotate( + "check that the deployment trash dir and the directory you want to trash are on the same device" + ) + raise e