[pve-devel] [PATCH pve-client 1/2] Helpers.pm: new helper configuration_directory

Dietmar Maurer dietmar at proxmox.com
Fri Jun 15 07:46:43 CEST 2018


Read configs from XDG_CONFIG_HOME/pveclient/ first.
if XDG_CONFIG_HOME is not set, then use $HOME/.config/pveclient/

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/APIClient/Helpers.pm | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/PVE/APIClient/Helpers.pm b/PVE/APIClient/Helpers.pm
index cc19514..8a96e81 100644
--- a/PVE/APIClient/Helpers.pm
+++ b/PVE/APIClient/Helpers.pm
@@ -273,4 +273,18 @@ sub poll_task {
     return $task_status->{exitstatus};
 }
 
+sub configuration_directory {
+
+    my $home = $ENV{HOME} // '';
+    my $xdg = $ENV{XDG_CONFIG_HOME} // '';
+
+    my $subdir = "pveclient";
+
+    return "$xdg/$subdir" if length($xdg);
+
+    return "$home/.config/$subdir" if length($home);
+
+    die "neither XDG_CONFIG_HOME nor HOME environment variable set\n";
+}
+
 1;
-- 
2.11.0




More information about the pve-devel mailing list