emms-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emms-patches] Avoid adding duplicates when dealing with symbolic links.


From: Stefan Kangas
Subject: [Emms-patches] Avoid adding duplicates when dealing with symbolic links.
Date: Mon, 08 Feb 2010 00:45:40 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Avoid adding duplicates when dealing with symbolic links.

The function `emms-source-file-directory-tree-internal' follows all
symlinks.  This patch addresses one case where this probably is not what
the user would want.  Consider the following directory hierarchy:

$ pwd
/home/skangas/music/incoming
$ ls -do Organismen*
drwxr-xr-x 2 skangas 4096 Jan 23 16:02 Organismen/
lrwxrwxrwx 1 skangas   35 Jan 30 16:45 Organismen.started -> 
/home/skangas/music/incoming/Organismen/

Currently, running either `emms-add-find' or `emms-add-directory-tree'
with default settings will add the files in the directory twice.  I
don't believe anyone would want what is in effect duplicates in their
play list.

I propose the following change: If a symbolic link is found in a
directory, it is followed only if it is pointing to a path that is not
below the directory that the user requested to add.

On the other hand, if there is a symlink to a path that is *not* below
the added directory, the user will surely want to add the files there.
Therefore, this behavior should probably stay unchanged.

Please consider this patch for inclusion.  Thanks.

 - Stefan Kangas

P.S.
Perhaps some background might help to explain why anyone would want to
do something like this with their file system.  In my case, I'm using
symbolic links to indicate the state of torrents, in order not to
accidentally move a directory pointed to by a torrent which is
incomplete or still seeding.

I might add I'm not the only one doing stuff like this, as is evidented
From this feature request for another media player:

http://bugzilla.songbirdnest.com/show_bug.cgi?id=15211

---
 lisp/emms-source-file.el |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/emms-source-file.el b/lisp/emms-source-file.el
index 1b0f039..91cd466 100644
--- a/lisp/emms-source-file.el
+++ b/lisp/emms-source-file.el
@@ -162,7 +162,7 @@ value of `emms-source-file-default-directory'."
                     (string-match emms-source-file-exclude-regexp file))
             (emms-playlist-insert-track
              (emms-track 'file file))))
-        (emms-source-file-directory-tree dir regex)))
+        (emms-source-file-directory-tree (expand-file-name dir) regex)))
 
 ;;;###autoload (autoload 'emms-play-dired "emms-source-file" nil t)
 ;;;###autoload (autoload 'emms-add-dired "emms-source-file" nil t)
@@ -199,7 +199,10 @@ This function uses only emacs functions, so it might be a 
bit slow."
     (while dirs
       (cond
        ((file-directory-p (car dirs))
-        (if (string-match "/\\.\\.?$" (car dirs))
+        (if (or (string-match "/\\.\\.?$" (car dirs))
+                (let ((symlink (file-symlink-p (car dirs))))
+                  (and symlink
+                       (string-equal dir (substring symlink 0 (string-width 
dir))))))
             (setq dirs (cdr dirs))
           (setq dirs
                 (condition-case nil
-- 
1.6.6.1

Attachment: pgplrpDyuWurs.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]