From 9b3bf149ac37d34279c71b388c22a67ef88a84a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Droz?= Date: Fri, 20 Feb 2015 09:45:46 -0800 Subject: [PATCH] feeds: follow symlinks of datafile and configfile MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use case, configfile contains sensible data, and is in a specific directory, and $XDG_CONFIG_HOME is a symlink. When configfile is saved (rewritten + renamed), we want don't want to overwrite the symlink itself but the original file. The same applies for datafile. Signed-off-by: Raphaël Droz Signed-off-by: W. Trevor King --- rss2email/feeds.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rss2email/feeds.py b/rss2email/feeds.py index 5a9b9cc..a4540d6 100644 --- a/rss2email/feeds.py +++ b/rss2email/feeds.py @@ -135,7 +135,7 @@ class Feeds (list): self.configfiles = configfiles if datafile is None: datafile = self._get_datafile() - self.datafile = datafile + self.datafile = _os.path.realpath(datafile) if config is None: config = _config.CONFIG self.config = config @@ -338,18 +338,19 @@ class Feeds (list): version, self.datafile_version)) def save(self): - _LOG.debug('save feed configuration to {}'.format(self.configfiles[-1])) + dst_config_file = _os.path.realpath(self.configfiles[-1]) + _LOG.debug('save feed configuration to {}'.format(dst_config_file)) for feed in self: feed.save_to_config() - dirname = _os.path.dirname(self.configfiles[-1]) + dirname = _os.path.dirname(dst_config_file) if dirname and not _os.path.isdir(dirname): _os.makedirs(dirname, mode=0o700, exist_ok=True) - tmpfile = self.configfiles[-1] + '.tmp' + tmpfile = dst_config_file + '.tmp' with open(tmpfile, 'w') as f: self.config.write(f) f.flush() _os.fsync(f.fileno()) - _os.rename(tmpfile, self.configfiles[-1]) + _os.rename(tmpfile, dst_config_file) self._save_feeds() def _save_feeds(self): -- 2.26.2