tramp-devel
[Top][All Lists]
Advanced

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

Finding buffers visiting TRAMP sudo files


From: Basil L. Contovounesios
Subject: Finding buffers visiting TRAMP sudo files
Date: Tue, 24 Oct 2017 21:00:28 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

I recently asked a relatively involved question[1]
pertaining to TRAMP on the Emacs Stack Exchange forum, after
which it was suggested I ask it here instead. A modified
transcript of my question follows:

### Background

I am trying to write a function which, given the plain,
non-TRAMP-qualified filename of a recently opened file,
returns the associated buffer visiting that file.

### Issue

Normally the function find-buffer-visiting (or even the
simpler get-file-buffer) is up to this challenge, but not so
when the file has been opened via TRAMP sudo syntax.

### Observations

As an example, when opening the write-protected file
/etc/mpd.conf, with inode 123 and device number 456 on host
foo, as /sudo::/etc/mpd.conf, I observe the following:

  (get-buffer "/etc/mpd.conf")
      ⇒ #<buffer /etc/mpd.conf>

  (get-file-buffer "/etc/mpd.conf")
      ⇒ nil

  (find-buffer-visiting "/etc/mpd.conf")
      ⇒ nil

  (nthcdr 10 (file-attributes "/etc/mpd.conf"))
      ⇒ (123 456)

Inside the file's corresponding buffer:

  buffer-file-name
      ⇒ #("/sudo:address@hidden:/etc/mpd.conf"
          6 10 (tramp-default t))

  (equal buffer-file-name buffer-file-truename)
      ⇒ t

  buffer-file-number
      ⇒ (123 (-1 . 1))

### Diagnosis

AFAICT, (find-buffer-visiting "/etc/mpd.conf") fails when
the file has been opened via TRAMP because the function
compares:

a) the given plain filename with the TRAMP-qualified values
   of buffer-file-{,true}name; and

b) both inode and device numbers to determine file equality,
   but opening a file via TRAMP seems to modify its device
   number.

### Questions

1) Why does the file-attribute-device-number of
   TRAMP-visited files change? Is this necessary?

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?

3) Given a plain, non-TRAMP-qualified filename, how can I
   lookup a TRAMP buffer visiting it?

3.1 How do I get find-buffer-visiting to work with TRAMP
    buffers?

TIA for any and all help with or insights on this.

Footnotes: 
[1]  https://emacs.stackexchange.com/q/36371/15748

-- 
Basil



reply via email to

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