wking / rss2email

open-source tool for Windows, Mac OS and UNIX for getting news from RSS feeds in email
http://pypi.python.org/pypi/rss2email/
GNU General Public License v2.0
270 stars 48 forks source link

follow symlinks of datafile and configfile #49

Closed drzraf closed 9 years ago

drzraf commented 9 years ago

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. The attached patch (against Debian Jessie's r2e 3.9) addresses both issues:

--- feeds.py.orig   2015-02-20 14:18:04.804324947 -0300
+++ feeds.py    2015-02-20 14:33:59.101057048 -0300
@@ -135,7 +135,8 @@
         self.configfiles = configfiles
         if datafile is None:
             datafile = self._get_datafile()
-        self.datafile = datafile
+        # for unix, follow symlinks to create tmp dat file in the user-expected directory
+        self.datafile = _os.path.realpath(datafile)
         if config is None:
             config = _config.CONFIG
         self.config = config
@@ -338,18 +339,19 @@
                 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):
wking commented 9 years ago

On Fri, Feb 20, 2015 at 09:45:46AM -0800, Raphaël Droz wrote:

The attached patch (against Debian Jessie's r2e 3.9) addresses both issues:

Looks good to me :). Can you open a pull request with this patch as a commit? Or should I create the commit for you? In either case, I'll need your Signed-off-by to land it. See 1 for details.

drzraf commented 9 years ago

On Wed, Feb 25, 2015 at 10:17:01AM -0800, W. Trevor King wrote:

Or should I create the commit for you?

yes, please do it. I don't have any clone under the hang right now (and I secretly hope the patch will cleanly apply to master).

For the Signed-Off: Rapha�l Droz raphael.droz+floss@gmail.com And for an (ideal) future: "I hereby accept the licence change to GPLv3 or later" "I hereby accept the licence change to AGPLv3 or later" (preferred) :)

drzraf commented 9 years ago

Seems that Github "Reply by email" assume UTF-8 even in presence of

Content-Type: text/plain; charset=iso-8859-1

The firstname should (obviously ?) be read "Raphaël", sorry

wking commented 9 years ago

On Wed, Feb 25, 2015 at 04:18:59PM -0800, Raphaël Droz wrote:

Wed, Feb 25, 2015 at 10:17:01AM -0800, W. Trevor King:

Or should I create the commit for you?

yes, please do it.

I've got that in a commit (9b3bf149, feeds: follow symlinks of datafile and configfile, 2015-02-20), which I pushed and then clawed back ;), because...

"I hereby accept the licence change to GPLv3 or later" "I hereby accept the licence change to AGPLv3 or later" (preferred) :)

You also need to accept GPLv2, since rss2email is under GPLv2 or (at your option) GPLv3. It's a weird choice inherited from rss2email v2.64 (2008-10-21, 1). I'd be fine with GPLv2+, but I'm not excited enough about it to figure out who's inherited Aaron Swartz's copyright and asking them if they're comfortable changing it. Can you ok the GPLv2?

drzraf commented 9 years ago

On Wed, Feb 25, 2015 at 04:42:27PM -0800, W. Trevor King wrote:

Can you ok the GPLv2?

Oh yes, I obviously accept the GPLv2 too! (I'm sorry to not have made it clear)

wking commented 9 years ago

Thanks :). I've pushed 9b3bf14 to master an I'm closing this issue. Please re-open if it doesn't work for some reason ;).