unofficial mirror of bug-gnu-emacs@gnu.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
Cc: Lars Ingebrigtsen <larsi@gnus.org>
Subject: bug#53638: [PATCH] newsticker better path handling and data storage
Date: Mon, 31 Jan 2022 20:09:58 +0000	[thread overview]
Message-ID: <875ypzhdkd.fsf@protonmail.com> (raw)
In-Reply-To: <87h79j29ha.fsf@gnus.org>

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

"Lars Ingebrigtsen" <larsi@gnus.org> writes:

> Can you rework the patch to use
> `expand-file-name', which is how file names are supposed to be constructed?

I've refactored it to use `expand-file-name' and `file-name-concat'. It
appears the current convention (correct me if I'm wrong) is to use
`expand-file-name' for joining only one path and one directory, and
`file-name-concat' for multiple together.


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

diff --git a/lisp/net/newst-backend.el b/lisp/net/newst-backend.el
index a62a7bd8b7..d3610a2130 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/"))
+  (file-name-as-directory
+    (expand-file-name "images" newsticker-dir)))
 
 (defun newsticker--icons-dir ()
   "Return directory where feed icons are saved."
-  (concat newsticker-dir "/icons/"))
+  (file-name-as-directory
+    (expand-file-name "icons" newsticker-dir)))
 
 (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"))
+  (file-name-as-directory
+    (expand-file-name "feeds" newsticker-dir)))
 
 (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 (file-name-as-directory
+               (expand-file-name (symbol-name (car feed))
+                                 (newsticker--cache-dir))))
+        (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 (expand-file-name "data" dir)
         (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 (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,18 @@ 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 (file-name-as-directory
+                           (file-name-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 +2368,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 +2377,11 @@ newsticker-download-enclosures
         (enclosure (newsticker--enclosure item)))
     (when enclosure
       (let ((url (cdr (assoc 'url enclosure)))
-            (temp-dir (concat "~/tmp/newsticker/" feedname "/" title))
+            (temp-dir (file-name-as-directory
+                        (file-name-concat temporary-file-directory
+                                          "newsticker"
+                                          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..f90a03873f 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 (expand-file-name "groups"
+                                                    newsticker-dir)))
+        (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-31 20:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-30 19:47 bug#53638: [PATCH] newsticker better path handling and data storage mailj2--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-31 10:23 ` 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 [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=875ypzhdkd.fsf@protonmail.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=53638@debbugs.gnu.org \
    --cc=larsi@gnus.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).