bugGNU nano - Bugs: bug #62244, when the working dir is gone, a...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #62244: when the working dir is gone, a different file than the intended one can be opened

Submitter:  Benno Schulenberg <bens>
Submitted:  Fri 01 Apr 2022 09:54:29 AM UTC
   
 
Severity:  3 - Normal Status:  Fixed
Assigned to:  bens Open/Closed:  Closed

Jump to the original submission

Fri 29 Apr 2022 07:35:09 AM UTC, comment #6: 

Released in nano-6.3.

Benno Schulenberg <bens>
Group administrator
Tue 05 Apr 2022 02:29:09 PM UTC, comment #5: 

The warning about a non-existent working directory has been added in the subsequent commit, 940b5eaa.

Benno Schulenberg <bens>
Group administrator
Mon 04 Apr 2022 10:54:36 AM UTC, comment #4: 

Fixed in git, commit fdd946c0, by using realpath().

Benno Schulenberg <bens>
Group administrator
Mon 04 Apr 2022 10:51:37 AM UTC, comment #3: 

A variant of the problem can be seen when the working directory disappears while nano has already opened a file in this directory.  Do for example:

mkdir folder
cd folder
echo parent >../seeme
echo subdir >seeme
nano seeme

Then, in a different terminal, remove the 'folder' directory.
Then type in nano: ^S.  See that nano reports that the file on disk has changed, and prompts: "File was modified since you opened it; continue saving?".  This is majorly confusing, but the user will probably answer Y -- with the result of overwriting the 'seeme' file in the parent dir of the former 'folder'.  Not good.

Benno Schulenberg <bens>
Group administrator
Mon 04 Apr 2022 10:37:06 AM UTC, comment #2: 

Bug was introduced sixteen years ago, by commit 85e35e67, as a reponse to this report from Mike Frysinger: https://lists.gnu.org/archive/html/nano-devel/2006-07/msg00000.html.

Benno Schulenberg <bens>
Group administrator
Fri 01 Apr 2022 03:09:51 PM UTC, comment #1: 

The problem is that, when the working directory has disappeared, get_full_path() will silently change the current directory to the first higher directory that still does exist.  This is wrong, of course, but nano has done this since about forever.  That no one complained is probably because a disappearing working directory almost never happens, and when it does happen, nano saves the current buffer in a parent dir, which is kind of convenient, even when incorrect.

Problem was found, of course, after making the patch that starts to use realpath().  The attached patch prevents the wrong file from being opened.  A subsequent patch might add a warning somewhere (during file opening) that the current directory is gone.

(file #53030)

Benno Schulenberg <bens>
Group administrator
Fri 01 Apr 2022 09:54:29 AM UTC, original submission:  

When the current working directory has somehow disappeared, trying to open a file that was located in this directory (or in a parental directory) will lead nano to open a different file instead.

To reproduce, run the following:

mkdir folder
cd folder
echo parent >../seeme
echo subdir >seeme
rm -rf ../folder
nano -Ix seeme

See that nano has opened the 'seeme' file in the parent directory instead of a file in the 'folder' directory.  This is wrong.  Some other editors (pico, joe, vim) will notice the absence of 'seeme' in the working directory and will simply open a new file -- an empty buffer -- and will report a problem when trying to save this buffer.  Editor 'fte' will crash when trying to open 'seeme', and 'lpe' will lock when trying to save the new buffer.  Editor 'ne' will report that it cannot open the file, and will report the same when trying to save the buffer.  The nicest is 'dte': it says that there is an error opening 'seeme': "Directory does not exist".  Nano should do something similar.  But at least it should not open the wrong file.

An older emacs will open an empty buffer and cryptically report "Wrong type argument: stringp, nil" -- only upon exit there is an "Error getting directory: No such file or directory" message on the terminal. 

Now, exit from nano, and instead of 'nano -Ix seeme', run:

nano -Ix ../seeme

See that nano says "New File".  This is wrong: it should have opened the file in the parent dir of 'folder'.

Expected behavior: when the working directory is gone, nano should simply open an empty buffer and report that the 'folder' directory does not exist.  In other words: it should behave similar to when the full path to the 'folder/seeme' file was specified.  In the latter case, nano will report something like: "Directory '/some/path/folder' does not exist".

Benno Schulenberg <bens>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-29 bens Open/ClosedOpen Closed
    2022-04-04 bens StatusIn Progress Fixed
    2022-04-01 bens Attached File- Added 0001-tweaks-make-use-of-realpath-in-our-get_full_path-fun.patch, #53030
        StatusNone In Progress
        Summarynano can open a different file than the intended one when the working dir is gone, a different file than the intended one can be opened

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code