diff --git a/docs/changelog.rst b/docs/changelog.rst index 362bcc3d0..fd6137cd2 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -253,6 +253,9 @@ Detailed list of changes - Remote control: Fix ``kitten @ action --match`` ignoring the match and running the action on the active window (:iss:`10672`) +- diff kitten: Fix comparing remote directories over SSH failing when they + contain read-only directories (:pull:`10676`) + - Graphics protocol: Add two new :ref:`indexed color image formats ` whose pixels are indices into the terminal color palette, so that images automatically change color along with the terminal diff --git a/kittens/diff/main.go b/kittens/diff/main.go index ba9a9c3e7..33eb9e4bd 100644 --- a/kittens/diff/main.go +++ b/kittens/diff/main.go @@ -153,7 +153,8 @@ func main(_ *cli.Command, opts_ *Options, args []string) (rc int, err error) { init_caches() defer func() { for tdir := range remote_dirs { - // Directories extracted from the remote host can be read-only + // Directories extracted from the remote host can be read-only. + // This is best effort cleanup of a temp dir, so errors are ignored. _ = filepath.WalkDir(tdir, func(path string, d fs.DirEntry, err error) error { if err == nil && d.IsDir() { _ = os.Chmod(path, 0o700) diff --git a/tools/utils/tar.go b/tools/utils/tar.go index 616d33978..5937d6cdc 100644 --- a/tools/utils/tar.go +++ b/tools/utils/tar.go @@ -400,8 +400,10 @@ func ExtractAllFromTar(tr *tar.Reader, dest_path string, optss ...TarExtractOpti } } } - for _, chmod := range dir_chmods { - if err = chmod(); err != nil { + // Apply in reverse so that children are processed before their parents, + // as a parent without search permission prevents chmod of its children + for i := len(dir_chmods) - 1; i >= 0; i-- { + if err = dir_chmods[i](); err != nil { return } } diff --git a/tools/utils/tar_test.go b/tools/utils/tar_test.go index c62660032..fa318b688 100644 --- a/tools/utils/tar_test.go +++ b/tools/utils/tar_test.go @@ -276,3 +276,36 @@ func TestTarExtractReadOnlyDirectory(t *testing.T) { t.Fatalf("Permissions of read-only directory not preserved: %v", st.Mode()) } } + +func TestTarExtractUnsearchableParentDirectory(t *testing.T) { + dest := t.TempDir() + parent := filepath.Join(dest, "a") + t.Cleanup(func() { + _ = os.Chmod(parent, 0700) + _ = os.Chmod(filepath.Join(parent, "b"), 0700) + }) + if _, err := ExtractAllFromTar(make_tar(t, + tar_entry{name: "a/", typeflag: tar.TypeDir, mode: 0600}, + tar_entry{name: "a/b/", typeflag: tar.TypeDir, mode: 0555}, + tar_entry{name: "a/b/file.txt", body: "contents"}, + ), dest); err != nil { + t.Fatal(err) + } + st, err := os.Stat(parent) + if err != nil { + t.Fatal(err) + } + if st.Mode().Perm() != 0600 { + t.Fatalf("Permissions of parent directory not preserved: %v", st.Mode()) + } + if err = os.Chmod(parent, 0700); err != nil { + t.Fatal(err) + } + assert_file_contents(t, filepath.Join(parent, "b", "file.txt"), "contents") + if st, err = os.Stat(filepath.Join(parent, "b")); err != nil { + t.Fatal(err) + } + if st.Mode().Perm() != 0555 { + t.Fatalf("Permissions of child directory not preserved: %v", st.Mode()) + } +}