Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/fs: Unit test to remove read only Windows files (#3744) #8651

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/fs/basicfs_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
"os"
"path/filepath"
"strings"
"syscall"
"testing"

"github.com/syncthing/syncthing/lib/build"
)

func TestWindowsPaths(t *testing.T) {
Expand Down Expand Up @@ -192,3 +195,31 @@ func TestGetFinalPath(t *testing.T) {
}
}
}

func TestRemoveWindowsDirIcon(t *testing.T) {

if !build.IsWindows {
t.Skip("only Windows")
return
}

fs, dir := setup(t)
relativePath := "folder_with_icon"
path := filepath.Join(dir, relativePath)

//Try to delete a folder with a custom icon with os.Remove (simulated by the readonly file attribute)
err := os.Mkdir(path, os.ModeDir)

a, e := syscall.UTF16PtrFromString(path)
if e == nil {
syscall.SetFileAttributes(a, uint32(syscall.FILE_ATTRIBUTE_DIRECTORY+syscall.FILE_ATTRIBUTE_READONLY))
} else {
t.Fatal(e)
}

err = fs.Remove(relativePath)

if err != nil {
t.Fatal(err)
}
}