From: Raphaël Droz Date: Fri, 20 Feb 2015 17:45:46 +0000 (-0800) Subject: feeds: follow symlinks of datafile and configfile X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9b3bf149ac37d34279c71b388c22a67ef88a84a7;p=rss2email.git feeds: follow symlinks of datafile and configfile 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 --- 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):