mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-20 07:02:28 +00:00
dnd kitten: Fix filesystem case sensitivity never being detected
is_case_sensitive_filesystem lost its true default when it moved into the dnd struct, so remote drops always treated names differing only in case as conflicting. Detect it properly and also probe for Unicode normalization aliasing, since a case sensitive filesystem can still treat differently normalized names as the same.
This commit is contained in:
parent
1647103c57
commit
cb88028abd
3 changed files with 56 additions and 5 deletions
|
|
@ -410,7 +410,9 @@ Detailed list of changes
|
|||
equivalent file and directory names on filesystems that treat them as
|
||||
aliases. Also list the existing files that will be overwritten under their
|
||||
actual names, including files inside symlinked directories, and fix dropping
|
||||
a directory over an existing file (:pull:`10772`)
|
||||
a directory over an existing file. Also no longer rename remotely dropped
|
||||
files whose names differ only in case on case sensitive filesystems
|
||||
(:pull:`10772`)
|
||||
|
||||
- Clipboard kitten: Fix a race when replacing an existing output file and
|
||||
losing the original file if writing it fails. Also preserve the permissions
|
||||
|
|
|
|||
|
|
@ -1122,3 +1122,33 @@ func equalStringSlices(a, b []string) bool {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// TestSetupBaseDirDetectsNameAliases verifies that setup_base_dir detects
|
||||
// whether the filesystem treats names differing in case or Unicode
|
||||
// normalization as aliases and leaves no probe files behind.
|
||||
func TestSetupBaseDirDetectsNameAliases(t *testing.T) {
|
||||
dest := t.TempDir()
|
||||
buildTree(t, dest, map[string]string{"Probe": "", "é": ""}, nil)
|
||||
_, cerr := os.Lstat(filepath.Join(dest, "probe"))
|
||||
_, nerr := os.Lstat(filepath.Join(dest, "é"))
|
||||
want := os.IsNotExist(cerr) && os.IsNotExist(nerr)
|
||||
for _, name := range []string{"Probe", "é"} {
|
||||
if err := os.Remove(filepath.Join(dest, name)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
d, err := runLocalDrop(t, dest, nil, copy_on_drop, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if d.is_case_sensitive_filesystem != want {
|
||||
t.Errorf("is_case_sensitive_filesystem: got %v, want %v", d.is_case_sensitive_filesystem, want)
|
||||
}
|
||||
entries, err := os.ReadDir(d.base_tempdir.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(entries) != 0 {
|
||||
t.Errorf("probe files left in the base temporary directory: %v", entries)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ package dnd
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"io"
|
||||
"io/fs"
|
||||
"maps"
|
||||
"net/url"
|
||||
"os"
|
||||
|
|
@ -90,7 +92,7 @@ type dnd struct {
|
|||
drop_output_dir *os.File
|
||||
base_tempdir *os.File
|
||||
tdir_counter int
|
||||
is_case_sensitive_filesystem bool
|
||||
is_case_sensitive_filesystem bool // false if names differing in case or Unicode normalization are aliases
|
||||
num_dropped_files int
|
||||
drag_status drag_status
|
||||
in_test_mode bool
|
||||
|
|
@ -131,12 +133,29 @@ func (dnd *dnd) setup_base_dir(base_dir string) (err error) {
|
|||
return err
|
||||
}
|
||||
dnd.base_tempdir = bf
|
||||
if _, serr := os.Stat(filepath.Join(base_dir, strings.ToUpper(filepath.Base(base_tdir)))); serr == nil {
|
||||
dnd.is_case_sensitive_filesystem = false
|
||||
}
|
||||
dnd.is_case_sensitive_filesystem = names_are_distinct(base_tdir)
|
||||
return err
|
||||
}
|
||||
|
||||
// Return true if names that differ only in case or Unicode normalization
|
||||
// refer to different entries in the empty directory dir. Any failure to
|
||||
// determine this is treated as them being aliases, which is the safe choice.
|
||||
func names_are_distinct(dir string) bool {
|
||||
is_absent := func(path string) bool {
|
||||
_, err := os.Lstat(path)
|
||||
return errors.Is(err, fs.ErrNotExist)
|
||||
}
|
||||
if !is_absent(filepath.Join(filepath.Dir(dir), strings.ToUpper(filepath.Base(dir)))) {
|
||||
return false
|
||||
}
|
||||
probe := filepath.Join(dir, "\u00e9")
|
||||
if err := os.WriteFile(probe, nil, 0o600); err != nil {
|
||||
return false
|
||||
}
|
||||
defer os.Remove(probe)
|
||||
return is_absent(filepath.Join(dir, "e\u0301"))
|
||||
}
|
||||
|
||||
func (dnd *dnd) remove_tdir() error {
|
||||
path := dnd.base_tempdir.Name()
|
||||
dnd.base_tempdir.Close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue