all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: mailj2--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 53638@debbugs.gnu.org
Subject: bug#53638: [PATCH] newsticker better path handling and data storage
Date: Sun, 30 Jan 2022 19:47:03 +0000	[thread overview]
Message-ID: <87h79lgg5n.fsf@protonmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 477 bytes --]


The way newsticker currently handles paths involves directly concating
"/", which only works for UNIX systems.

Additionally, since newsticker uses `prin1-to-string' for storing
groups and cache, it should be enforced that `print-level' and
`print-length' are set to nil for the operation just as a precaution (it
happened to me that I manually set these once, which resulted in the
newsticker cache being corrupted).

This patch should fix both of these issues.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: newsticker-patch.diff --]
[-- Type: text/x-patch; name=newsticker-patch.diff, Size: 5835 bytes --]

diff --git a/lisp/net/newst-backend.el b/lisp/net/newst-backend.el
index a62a7bd8b7..d4d2892da0 100644
--- a/lisp/net/newst-backend.el
+++ b/lisp/net/newst-backend.el
@@ -1697,11 +1697,13 @@ newsticker--update-process-ids
 ;; ======================================================================
 (defun newsticker--images-dir ()
   "Return directory where feed images are saved."
-  (concat newsticker-dir "/images/"))
+  (concat (file-name-as-directory newsticker-dir)
+          (file-name-as-directory "images")))
 
 (defun newsticker--icons-dir ()
   "Return directory where feed icons are saved."
-  (concat newsticker-dir "/icons/"))
+  (concat (file-name-as-directory newsticker-dir)
+          (file-name-as-directory "icons")))
 
 (defun newsticker--image-get (feed-name filename directory url)
   "Get image for FEED-NAME by returning FILENAME from DIRECTORY.
@@ -2114,7 +2116,8 @@ newsticker--cache-get-feed
 
 (defun newsticker--cache-dir ()
   "Return directory for saving cache data."
-  (concat newsticker-dir "/feeds"))
+  (concat (file-name-as-directory newsticker-dir)
+          (file-name-as-directory "feeds")))
 
 (defun newsticker--cache-save ()
   "Save cache data for all feeds."
@@ -2125,11 +2128,15 @@ newsticker--cache-save
 
 (defun newsticker--cache-save-feed (feed)
   "Save cache data for FEED."
-  (let ((dir (concat (newsticker--cache-dir) "/" (symbol-name (car feed)))))
+  (let ((dir (concat (newsticker--cache-dir)
+                     (symbol-name (car feed))))
+        (print-level nil)
+        (print-length nil))
     (unless (file-directory-p dir)
       (make-directory dir t))
     (let ((coding-system-for-write 'utf-8))
-      (with-temp-file (concat dir "/data")
+      (with-temp-file (concat (file-name-as-directory dir)
+                              "data")
         (insert ";; -*- coding: utf-8 -*-\n")
         (insert (prin1-to-string (cdr feed)))))))
 
@@ -2141,7 +2148,9 @@ newsticker--cache-read
 
 (defun newsticker--cache-read-feed (feed-name)
   "Read cache data for feed named FEED-NAME."
-  (let ((file-name (concat (newsticker--cache-dir) "/" feed-name "/data"))
+  (let ((file-name (concat (newsticker--cache-dir)
+                           feed-name
+                           "data"))
         (coding-system-for-read 'utf-8))
     (when (file-exists-p file-name)
       (with-temp-buffer
@@ -2334,14 +2343,17 @@ newsticker-download-images
   "Download the first image.
 If FEEDNAME equals \"imagefeed\" download the first image URL
 found in the description=contents of ITEM to the directory
-\"~/tmp/newsticker/FEEDNAME/TITLE\" where TITLE is the title of
+`temporary-file-directory'/newsticker/FEEDNAME/TITLE where TITLE is the title of
 the item."
   (when (string= feedname "imagefeed")
     (let ((title (newsticker--title item))
           (desc (newsticker--desc item)))
       (when (string-match "<img src=\"\\(http://[^ \"]+\\)\"" desc)
         (let ((url (substring desc (match-beginning 1) (match-end 1)))
-              (temp-dir (concat "~/tmp/newsticker/" feedname "/" title))
+              (temp-dir (concat (file-name-as-directory temporary-file-directory)
+                                (file-name-as-directory "newsticker")
+                                (file-name-as-directory feedname)
+                                title))
               (org-dir default-directory))
           (unless (file-directory-p temp-dir)
             (make-directory temp-dir t))
@@ -2355,7 +2367,8 @@ newsticker-download-images
 
 (defun newsticker-download-enclosures (feedname item)
   "In all feeds download the enclosed object of the news ITEM.
-The object is saved to the directory \"~/tmp/newsticker/FEEDNAME/TITLE\", which
+The object is saved to the directory
+`temporary-file-directory'/newsticker/FEEDNAME/TITLE, which
 is created if it does not exist.  TITLE is the title of the news
 item.  Argument FEEDNAME is ignored.
 This function is suited for adding it to `newsticker-new-item-functions'."
@@ -2363,7 +2376,10 @@ newsticker-download-enclosures
         (enclosure (newsticker--enclosure item)))
     (when enclosure
       (let ((url (cdr (assoc 'url enclosure)))
-            (temp-dir (concat "~/tmp/newsticker/" feedname "/" title))
+            (temp-dir (concat (file-name-as-directory temporary-file-directory)
+                              (file-name-as-directory "newsticker")
+                              (file-name-as-directory feedname)
+                              title))
             (org-dir default-directory))
         (unless (file-directory-p temp-dir)
           (make-directory temp-dir t))
diff --git a/lisp/net/newst-treeview.el b/lisp/net/newst-treeview.el
index 80d9fd1cef..f7cf153900 100644
--- a/lisp/net/newst-treeview.el
+++ b/lisp/net/newst-treeview.el
@@ -1257,7 +1257,10 @@ newsticker-treeview-save
   "Save treeview group settings."
   (interactive)
   (let ((coding-system-for-write 'utf-8)
-        (buf (find-file-noselect (concat newsticker-dir "/groups"))))
+        (buf (find-file-noselect (concat (file-name-as-directory newsticker-dir)
+                                         "groups")))
+        (print-length nil)
+        (print-level nil))
     (when buf
       (with-current-buffer buf
         (setq buffer-undo-list t)
@@ -1270,7 +1273,8 @@ newsticker-treeview-save
 (defun newsticker--treeview-load ()
   "Load treeview settings."
   (let* ((coding-system-for-read 'utf-8)
-         (filename (concat newsticker-dir "/groups"))
+         (filename (concat (file-name-as-directory newsticker-dir)
+                           "groups"))
          (buf (and (file-exists-p filename)
                    (find-file-noselect filename))))
     (when buf

             reply	other threads:[~2022-01-30 19:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-30 19:47 mailj2--- via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-01-31 10:23 ` bug#53638: [PATCH] newsticker better path handling and data storage Robert Pluim
2022-01-31 12:19 ` Eli Zaretskii
2022-01-31 15:47 ` Lars Ingebrigtsen
2022-01-31 20:09   ` mailj2--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-01  3:25     ` Eli Zaretskii
2022-05-16  3:50 ` bug#53638: [PATCH] newsticker better path handling and data Xavier Capaldi
2022-05-16 12:04   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h79lgg5n.fsf@protonmail.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=53638@debbugs.gnu.org \
    --cc=mailj2@protonmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.