The temporary archive was chmodded to 0644, so replacing a private 0600 archive made it world-readable (QA-6). A replaced archive now keeps its permissions; a new one gets 0666 minus the umask, as before the temp-file change. The temp name embedded the archive name, so names near NAME_MAX failed with ENAMETOOLONG (QA-7). It is now a short fixed-length .vcom-tmp-<rand>. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
689 B
Go
26 lines
689 B
Go
package vfs
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// QA-6: a new archive gets 0666 minus umask (as os.Create would), not the
|
|
// 0600 of the temp file and not a fixed 0644.
|
|
func TestNewArchiveModeFollowsUmask(t *testing.T) {
|
|
d, out := t.TempDir(), t.TempDir()
|
|
qaWrite(t, filepath.Join(d, "a.txt"), "x", 0o644)
|
|
arc := filepath.Join(out, "a.tar")
|
|
if err := CreateArchive(context.Background(), []string{filepath.Join(d, "a.txt")}, arc, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
st, err := os.Stat(arc)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := 0o666 &^ processUmask(); st.Mode().Perm() != want {
|
|
t.Fatalf("new archive mode %o, want %o", st.Mode().Perm(), want)
|
|
}
|
|
}
|