Skip to content

Commit 4142242

Browse files
authored
Merge pull request #389 from zb140/fix-recursive-add
Fix recursive add
2 parents 77b8641 + f276df1 commit 4142242

File tree

3 files changed

+24
-37
lines changed

3 files changed

+24
-37
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
linters:
22
enable-all: true
33
disable:
4-
- goconst
54
- gocyclo
65
- lll
76
- maligned

cmd/add_test.go

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"runtime"
54
"testing"
65

76
"github.com/stretchr/testify/assert"
@@ -45,12 +44,11 @@ func TestAddAfterModification(t *testing.T) {
4544

4645
func TestAddCommand(t *testing.T) {
4746
for _, tc := range []struct {
48-
name string
49-
skipOnWindows bool
50-
args []string
51-
add addCmdConfig
52-
root interface{}
53-
tests interface{}
47+
name string
48+
args []string
49+
add addCmdConfig
50+
root interface{}
51+
tests interface{}
5452
}{
5553
{
5654
name: "add_first_file",
@@ -90,9 +88,8 @@ func TestAddCommand(t *testing.T) {
9088
},
9189
},
9290
{
93-
name: "add_recursive",
94-
skipOnWindows: true,
95-
args: []string{"/home/user/.config"},
91+
name: "add_recursive",
92+
args: []string{"/home/user/.config"},
9693
add: addCmdConfig{
9794
recursive: true,
9895
},
@@ -109,9 +106,8 @@ func TestAddCommand(t *testing.T) {
109106
},
110107
},
111108
{
112-
name: "add_nested_directory",
113-
skipOnWindows: true,
114-
args: []string{"/home/user/.config/micro/settings.json"},
109+
name: "add_nested_directory",
110+
args: []string{"/home/user/.config/micro/settings.json"},
115111
root: map[string]interface{}{
116112
"/home/user": &vfst.Dir{Perm: 0755},
117113
"/home/user/.chezmoi": &vfst.Dir{Perm: 0700},
@@ -125,9 +121,8 @@ func TestAddCommand(t *testing.T) {
125121
},
126122
},
127123
{
128-
name: "add_exact_dir",
129-
skipOnWindows: true,
130-
args: []string{"/home/user/dir"},
124+
name: "add_exact_dir",
125+
args: []string{"/home/user/dir"},
131126
add: addCmdConfig{
132127
options: chezmoi.AddOptions{
133128
Exact: true,
@@ -145,9 +140,8 @@ func TestAddCommand(t *testing.T) {
145140
},
146141
},
147142
{
148-
name: "add_exact_dir_recursive",
149-
skipOnWindows: true,
150-
args: []string{"/home/user/dir"},
143+
name: "add_exact_dir_recursive",
144+
args: []string{"/home/user/dir"},
151145
add: addCmdConfig{
152146
recursive: true,
153147
options: chezmoi.AddOptions{
@@ -250,9 +244,8 @@ func TestAddCommand(t *testing.T) {
250244
},
251245
},
252246
{
253-
name: "add_symlink_in_dir_recursive",
254-
skipOnWindows: true,
255-
args: []string{"/home/user/foo"},
247+
name: "add_symlink_in_dir_recursive",
248+
args: []string{"/home/user/foo"},
256249
add: addCmdConfig{
257250
recursive: true,
258251
},
@@ -272,9 +265,8 @@ func TestAddCommand(t *testing.T) {
272265
},
273266
},
274267
{
275-
name: "add_symlink_with_parent_dir",
276-
skipOnWindows: true,
277-
args: []string{"/home/user/foo/bar/baz"},
268+
name: "add_symlink_with_parent_dir",
269+
args: []string{"/home/user/foo/bar/baz"},
278270
root: map[string]interface{}{
279271
"/home/user": &vfst.Dir{Perm: 0755},
280272
"/home/user/.chezmoi": &vfst.Dir{Perm: 0700},
@@ -313,9 +305,8 @@ func TestAddCommand(t *testing.T) {
313305
},
314306
},
315307
{
316-
name: "dont_add_ignored_file_recursive",
317-
skipOnWindows: true,
318-
args: []string{"/home/user/foo"},
308+
name: "dont_add_ignored_file_recursive",
309+
args: []string{"/home/user/foo"},
319310
add: addCmdConfig{
320311
recursive: true,
321312
},
@@ -373,9 +364,6 @@ func TestAddCommand(t *testing.T) {
373364
},
374365
} {
375366
t.Run(tc.name, func(t *testing.T) {
376-
if runtime.GOOS == "windows" && tc.skipOnWindows {
377-
t.Skip("add --recursive is broken on windows")
378-
}
379367
c := &Config{
380368
SourceDir: "/home/user/.chezmoi",
381369
DestDir: "/home/user",
@@ -401,9 +389,6 @@ func TestAddCommand(t *testing.T) {
401389
}
402390

403391
func TestIssue192(t *testing.T) {
404-
if runtime.GOOS == "windows" {
405-
t.Skip("add --recursive is broken on windows")
406-
}
407392
root := []interface{}{
408393
map[string]interface{}{
409394
"/local/home/offbyone": &vfst.Dir{

lib/chezmoi/private_windows.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func resolveSymlink(file string) (string, error) {
4242
return resolved, nil
4343
}
4444

45+
// IsPrivate returns whether path is private. A path is considered private when
46+
// its mode has been explicitly set to some value (ie, it's non-zero) and that
47+
// value disallows access to the special "Everyone" user
4548
func IsPrivate(fs PrivacyStater, path string) (bool, error) {
4649
rawPath, err := fs.RawPath(path)
4750
if err != nil {
@@ -53,10 +56,10 @@ func IsPrivate(fs PrivacyStater, path string) (bool, error) {
5356
return false, err
5457
}
5558

56-
mode, err := acl.GetEffectiveAccessMode(resolvedPath)
59+
mode, err := acl.GetExplicitAccessMode(resolvedPath)
5760
if err != nil {
5861
return false, err
5962
}
6063

61-
return mode&07 == 0, nil
64+
return (mode != 0) && (mode&07) == 0, nil
6265
}

0 commit comments

Comments
 (0)