Don't sync symlink folders (#205)

Fixes https://github.com/databricks/databricks-vscode/issues/452
This commit is contained in:
Fabian Jakobs 2023-02-15 17:02:54 +01:00 committed by GitHub
parent 3851b59bbd
commit 8c1b620b17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package fileset
import (
"fmt"
"io/fs"
"os"
"path/filepath"
)
@ -55,6 +56,15 @@ func (w *FileSet) RecursiveListFiles(dir string) (fileList []File, err error) {
return err
}
// skip symlinks
info, err := d.Info()
if err != nil {
return err
}
if info.Mode()&os.ModeSymlink != 0 {
return nil
}
if d.IsDir() {
ign, err := w.ignore.IgnoreDirectory(relPath)
if err != nil {

View File

@ -83,6 +83,33 @@ func TestDiff(t *testing.T) {
assert.Equal(t, map[string]string{"world.txt": "world.txt"}, state.RemoteToLocalNames)
}
func TestSymlinkDiff(t *testing.T) {
// Create temp project dir
projectDir := t.TempDir()
fileSet, err := git.NewFileSet(projectDir)
require.NoError(t, err)
state := Snapshot{
LastUpdatedTimes: make(map[string]time.Time),
LocalToRemoteNames: make(map[string]string),
RemoteToLocalNames: make(map[string]string),
}
err = os.Mkdir(filepath.Join(projectDir, "foo"), os.ModePerm)
assert.NoError(t, err)
f1 := testfile.CreateFile(t, filepath.Join(projectDir, "foo", "hello.txt"))
defer f1.Close(t)
err = os.Symlink(filepath.Join(projectDir, "foo"), filepath.Join(projectDir, "bar"))
assert.NoError(t, err)
files, err := fileSet.All()
assert.NoError(t, err)
change, err := state.diff(files)
assert.NoError(t, err)
assert.Len(t, change.put, 1)
}
func TestFolderDiff(t *testing.T) {
// Create temp project dir
projectDir := t.TempDir()