tramp-devel
[Top][All Lists]
Advanced

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

Re: Finding buffers visiting TRAMP sudo files


From: Basil L. Contovounesios
Subject: Re: Finding buffers visiting TRAMP sudo files
Date: Fri, 27 Oct 2017 12:47:57 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

On Fri, Oct 27 2017, at 11:09, Michael Albinus <address@hidden> wrote:

Thank you for getting back to me Michael.

> which Emacs / Tramp versions are you using? 

I am running a 2017-10-26 build of the master branch,
i.e. Emacs 27.0.50 with Tramp 2.3.3-pre.

> Since I have no file /etc/mpd.conf, I use /etc/pam.conf
> instead.

That's fine; I only specified this particular file for
illustrative purposes.  I will hereafter use /etc/pam.conf.

>>   (get-buffer "/etc/mpd.conf")
>>       ⇒ #<buffer /etc/mpd.conf>
>
> This does not work, the buffer name is "pam.conf". I must
> call
>
>   (get-buffer "pam.conf")
>       ⇒ #<buffer pam.conf>

Sorry, silly mistake on my part - the buffer name
"/etc/mpd.conf" is a result of my uniquification settings; I
should have used examples from a bare Emacs session, in
which I get the same result as you.

>>   (nthcdr 10 (file-attributes "/etc/mpd.conf"))
>>       ⇒ (123 456)
>
> Same here. However, for Emacs (Tramp), the files
> "/etc/pam.conf" and "/sudo::/etc/pam.conf" are different.
> And so are the inode numbers. Well, this is not a must
> (since the device numbers differ anyway), but it's the
> current implementation.

[...]

> Maybe one could argue that the inode number shall equal
> for both files, but the device numbers must differ.

Hmm, for me on GNU/Linux the device numbers are indeed
different but the inode number is always the same:

  (equal (file-attribute-inode-number
          (file-attributes "/etc/pam.conf"))
         (file-attribute-inode-number
          (file-attributes "/sudo::/etc/pam.conf")))
      ⇒ t

  (equal (file-attribute-device-number
          (file-attributes "/etc/pam.conf"))
         (file-attribute-device-number
          (file-attributes "/sudo::/etc/pam.conf")))
      ⇒ nil

Is there anything unusual about this?

> "/etc/pam.conf" and "/sudo::/etc/pam.conf" are different
> files for Emacs (Tramp).

Understandable.

>> 2) Does TRAMP provide a means of comparing visited files for
>>    equality independently of TRAMP method, or at least for
>>    particular TRAMP methods, e.g. sudo?
>
> What do you mean "comparing"? Whether the files are equal?
> Plain Emacs functionality, like diff or ediff, exists.
>
> If both files are already loaded in buffers, you could
> compare them via `compare-buffer-substrings' and friends.
>
> Tramp does not offer special functionality for this. After
> all, Tramp is just a library, which carries alternative
> implementations of some basic file operations.
>
> What else do you need?

By "comparing" e.g. "/etc/pam.conf" and
"/sudo::/etc/pam.conf" I mean determining whether they
ultimately name the same file, as per file-equal-p.  This is
answered to an extent by the fact that Emacs fundamentally
considers the files as being different.  I am not interested
in comparing file or buffer contents.

>> 3) Given a plain, non-TRAMP-qualified filename, how can I
>>    lookup a TRAMP buffer visiting it?
>
> Look for (concat "/sudo::" filename) or alike.

Thanks, this works and addresses my question (2) as well.

Kind regards,

-- 
Basil



reply via email to

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