From 84def4398f83b838503e8047c9e4a17698f96e7a Mon Sep 17 00:00:00 2001 From: Doug Luce Date: Thu, 3 Mar 2016 14:57:12 -0800 Subject: [PATCH 1/2] cronvar.py: support absolute destinations Mainly so /etc/crontab can be written to. --- system/cronvar.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) mode change 100644 => 100755 system/cronvar.py diff --git a/system/cronvar.py b/system/cronvar.py old mode 100644 new mode 100755 index b3b373e9dc3..1800cbd4bd4 --- a/system/cronvar.py +++ b/system/cronvar.py @@ -70,7 +70,9 @@ options: default: root cron_file: description: - - If specified, uses this file in cron.d instead of an individual user's crontab. + - If specified, uses this file instead of an individual user's crontab. + Without a leading /, this is assumed to be in /etc/cron.d. With a leading + /, this is taken as absolute. required: false default: null backup: @@ -126,7 +128,10 @@ class CronVar(object): self.wordchars = ''.join(chr(x) for x in range(128) if chr(x) not in ('=', "'", '"', )) if cron_file: - self.cron_file = '/etc/cron.d/%s' % cron_file + self.cron_file = "" + if cron_file[0] != '/': + self.cron_file = '/etc/cron.d/' + self.cron_file = self.cron_file + cron_file else: self.cron_file = None From 0298dac401e3981ecb1ba3ed43ef6e2d07f9882e Mon Sep 17 00:00:00 2001 From: Doug Luce Date: Thu, 3 Mar 2016 15:10:19 -0800 Subject: [PATCH 2/2] Use os module for checking absolute/joining paths --- system/cronvar.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/system/cronvar.py b/system/cronvar.py index 1800cbd4bd4..1068739c0d0 100755 --- a/system/cronvar.py +++ b/system/cronvar.py @@ -129,9 +129,10 @@ class CronVar(object): if cron_file: self.cron_file = "" - if cron_file[0] != '/': - self.cron_file = '/etc/cron.d/' - self.cron_file = self.cron_file + cron_file + if os.path.isabs(cron_file): + self.cron_file = cron_file + else: + self.cron_file = os.path.join('/etc/cron.d', cron_file) else: self.cron_file = None