unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Matt Armstrong <matt@rfc20.org>
Cc: 46397@debbugs.gnu.org, eggert@cs.ucla.edu, craven@gmx.net
Subject: bug#46397: 27.1; Cannot delete buffer pointing to a file in a path that includes a file
Date: Sat, 06 Mar 2021 11:36:58 +0200	[thread overview]
Message-ID: <83pn0cwrlx.fsf@gnu.org> (raw)
In-Reply-To: <87y2f1meeu.fsf@mdeb> (message from Matt Armstrong on Fri, 05 Mar 2021 14:19:53 -0800)

> From: Matt Armstrong <matt@rfc20.org>
> Cc: 46397@debbugs.gnu.org, eggert@cs.ucla.edu, craven@gmx.net
> Date: Fri, 05 Mar 2021 14:19:53 -0800
> 
> > As for the tests you posted: too many of them rely on Posix file
> > modes, and thus will probably either fail or be unable to provide
> > meaningful testing on MS-Windows.  Can we please augment that by tests
> > that create unlocking problems by, e.g., running a shell command to
> > remove or rename or otherwise sabotage the lock file, so that the new
> > functionality could be meaningfully tested on Windows as well?
> 
> I have not been able to come up with a way to achieve what you ask for.

I'm not yet sure I understand why.  I ask several questions about this
below.

> Another issue is that the lock file is typicaly a symbolink link, and
> operating systems typically ignore file modes on symbolic links

On MS-Windows, lock files aren't symlinks, they are regular files.
You should be able to see that in filelock.c.

> so it
> is hard to put the lock file itself into an "invalid" state --
> i.e. where simply attempting to access or delete it generates a file
> system level error.  This is why I resorted to modifying file modes on
> the containing directory -- attemps to remove or access files in such a
> directory do reliably generate errors (on POSIX systems).

I'm asking what is the difference, from the file-locking POV, between
an inaccessible directory and a directory that doesn't exist?  in both
cases, the directory and a lock file inside it are "inaccessible",
right?  So would we be able to make the same or similar tests by
deleting or renaming the directory with the lock file, as we do by
making the directory inaccessible?

> What I've done is make the tests skip themselves when `set-file-mode' on
> the test's temporary directory appears to not work.  When I test this on
> an ext2 file system the tests complete.  When I test this on a FAT and
> NTFS file system (set up as a ramdisk on GNU/Linux), the tests skip
> themselves.

That's exactly the issue: I'd like the tests to not be skipped on
Windows, at least some of them, so that the underlying functionality
could be tested there as well.

> +(defvar filelock-tests-temporary-file-directory nil
> +  "The directory for writing temporary files in filelock tests.
> +This is used by the function
> +`filelock-tests--make-temp-directory' to override the value of
> +the variable `temporary-file-directory'.")

Is this meant to be used to debug the tests?  If so, I suggest to
mention that, and the reason for overriding temporary-file-directory,
in the doc string.

> +(defun filelock-tests--make-temp-directory ()
> +  "Create and return the name of a temporary directory.
> +The caller should delete the directory."
> +  (let ((temporary-file-directory (or filelock-tests-temporary-file-directory
> +                                      temporary-file-directory)))
> +    (make-temp-file "test" t)))

Please use a name that is more indicative of this test, so that the
directory could be more easily spotted.

> +            (set-file-modes temp-dir (logior #o700 (file-modes temp-dir)))
> +            (set-buffer-modified-p nil)))
> +      (delete-directory temp-dir t nil))))

Should these be inside ignore-errors?  Or do you _want_ them to signal
errors if something goes wrong with the underlying file I/O calls?

> +(ert-deftest filelock-tests-lock-unlock-no-errors ()
> +  "Check that locking and unlocking works without error."
> +  (filelock-tests--fixture
> +   (lambda (_)
> +     (should (not (file-locked-p (buffer-file-name))))

ert has 'should-not', why don't you use it (here and elsewhere)?

> +(ert-deftest filelock-tests-lock-buffer-permission-denied ()
> +  "Check that locking a buffer in a directory with no write
> +permissions does not work."
> +  (filelock-tests--fixture
> +   (lambda (temp-dir)
> +     (should (not (file-locked-p (buffer-file-name))))
> +
> +     (let ((original-modes (file-modes temp-dir)))
> +       (skip-unless (filelock-tests--make-file-inaccessible temp-dir))
> +       ;; FIXME: file system errors when locking a file are ignored;
> +       ;; should they be?
> +       (insert "this locks the current buffer's file")
> +       (set-file-modes temp-dir original-modes))
> +
> +     (should (not (file-locked-p (buffer-file-name)))))))

Would this test work if, instead of making the directory inaccessible,
you renamed it to another name (and then renamed back)?  If not, why
not?

> +(ert-deftest filelock-tests-file-locked-p-permission-denied ()
> +  "Check that `file-locked-p' fails if the directory is inaccesible."
> +  (filelock-tests--fixture
> +   (lambda (temp-dir)
> +     (skip-unless (filelock-tests--make-file-inaccessible temp-dir))
> +
> +     (let ((err (should-error (file-locked-p (buffer-file-name)))))
> +       (should (equal (cl-subseq err 0 2)
> +                      '(file-error "Testing file lock")))))))

cl-subseq needs to require cl-extra, AFAICT.

> +     ;; Kill the current buffer even if it is modified.  Use advice to
> +     ;; fake a "yes" answer for the "Buffer modified; kill anyway?"

You don't need to use advice-add, you can simply override the
definition of yes-or-no-p.

Thanks.





  reply	other threads:[~2021-03-06  9:36 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09  9:47 bug#46397: 27.1; Cannot delete buffer pointing to a file in a path that includes a file Peter
2021-02-09 23:47 ` Matt Armstrong
2021-02-10  0:23   ` Matt Armstrong
2021-02-10 15:05     ` Eli Zaretskii
2021-02-10 19:23       ` Paul Eggert
2021-02-10 19:45         ` Eli Zaretskii
2021-02-10 22:39           ` Matt Armstrong
2021-02-12  7:43             ` Eli Zaretskii
2021-02-12  9:36               ` Paul Eggert
2021-02-12 11:33                 ` Eli Zaretskii
2021-02-12 23:59                   ` Matt Armstrong
2021-02-13  8:07                     ` Eli Zaretskii
2021-02-11 22:14         ` Matt Armstrong
2021-02-12  2:20           ` Paul Eggert
2021-02-12  7:15             ` Eli Zaretskii
2021-02-13  1:15               ` Matt Armstrong
2021-02-13  1:26                 ` Paul Eggert
2021-02-13  8:21                   ` Eli Zaretskii
2021-02-13  8:28                 ` Eli Zaretskii
2021-02-14  0:49                   ` Matt Armstrong
2021-02-14 19:22                     ` Eli Zaretskii
2021-02-14 22:16                       ` Matt Armstrong
2021-02-15 15:09                         ` Eli Zaretskii
2021-02-16  0:49                           ` Matt Armstrong
2021-02-16  1:55                             ` Paul Eggert
2021-02-16 15:06                               ` Eli Zaretskii
2021-02-16 11:53                             ` Lars Ingebrigtsen
2021-02-22 19:24                             ` bug#46397: [PATCH] " Matt Armstrong
2021-02-19 19:10                           ` Matt Armstrong
2021-02-19 19:23                             ` Eli Zaretskii
2021-02-19 21:46                               ` Matt Armstrong
2021-02-20  9:09                                 ` Eli Zaretskii
2021-02-21  0:36                                   ` Matt Armstrong
2021-02-21 23:43                                     ` Mike Kupfer
2021-02-22  1:42                                       ` Matt Armstrong
2021-03-14 18:03                                         ` Bill Wohler
2021-03-17 23:36                                           ` Matt Armstrong
2021-02-24 17:37                                     ` Matt Armstrong
2021-02-24 18:50                                       ` Eli Zaretskii
2021-03-01 16:59                                       ` Eli Zaretskii
2021-03-05 22:19                                         ` Matt Armstrong
2021-03-06  9:36                                           ` Eli Zaretskii [this message]
2021-03-06 23:39                                             ` Matt Armstrong
2021-03-07  2:50                                             ` Paul Eggert
2021-03-07  5:57                                               ` Matt Armstrong
2021-02-19 19:45                             ` Paul Eggert
2021-02-19 21:52                               ` Matt Armstrong
2021-03-08  2:18                               ` Matt Armstrong
2021-03-11 14:34                                 ` Eli Zaretskii
2021-03-17 23:49                                   ` Matt Armstrong
2021-03-17 23:51                                   ` Matt Armstrong
2021-03-20 10:43                                     ` Eli Zaretskii
2021-03-22  1:43                                       ` Matt Armstrong
2021-03-27  9:20                                         ` Eli Zaretskii
2021-02-10  0:26   ` Matt Armstrong

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=83pn0cwrlx.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=46397@debbugs.gnu.org \
    --cc=craven@gmx.net \
    --cc=eggert@cs.ucla.edu \
    --cc=matt@rfc20.org \
    /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).