From 37ebbb53be59fad87669ed35978c16ed2be1e5f8 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Mon, 17 Nov 2014 11:25:32 +0000 Subject: [PATCH 1/2] Replace directories/links with files (fixes #580) --- internal/model/puller.go | 20 ++++++++++++++------ test/filetype_test.go | 2 +- test/symlink_test.go | 6 ------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/internal/model/puller.go b/internal/model/puller.go index d4fbdc8cb..78abbbc32 100644 --- a/internal/model/puller.go +++ b/internal/model/puller.go @@ -370,12 +370,13 @@ func (p *Puller) handleDir(file protocol.FileInfo) { l.Debugf("need dir\n\t%v\n\t%v", file, curFile) } - info, err := os.Stat(realName) + info, err := os.Lstat(realName) + isLink, _ := symlinks.IsSymlink(realName) switch { - // There is already something under that name, but it's a file. - // Most likely a file is getting replaced with a directory. - // Remove the file and fall through to directory creation. - case err == nil && !info.IsDir(): + // There is already something under that name, but it's a file/link. + // Most likely a file/link is getting replaced with a directory. + // Remove the file/link and fall through to directory creation. + case isLink || (err == nil && !info.IsDir()): err = osutil.InWritableDir(os.Remove, realName) if err != nil { l.Infof("Puller (folder %q, dir %q): %v", p.folder, file.Name, err) @@ -795,7 +796,14 @@ func (p *Puller) finisherRoutine(in <-chan *sharedPullerState) { } } - // Replace the original file with the new one + // If the target path is a symlink or a directory, we cannot copy + // over it, hence remove it before proceeding. + stat, err := os.Lstat(state.realName) + isLink, _ := symlinks.IsSymlink(state.realName) + if isLink || (err == nil && stat.IsDir()) { + osutil.InWritableDir(os.Remove, state.realName) + } + // Replace the original content with the new one err = osutil.Rename(state.tempName, state.realName) if err != nil { l.Warnln("puller: final:", err) diff --git a/test/filetype_test.go b/test/filetype_test.go index 6d4285aac..df608bd29 100644 --- a/test/filetype_test.go +++ b/test/filetype_test.go @@ -16,7 +16,7 @@ // +build integration // This currently fails; it should be fixed -package integration_test_disabled +package integration_test import ( "log" diff --git a/test/symlink_test.go b/test/symlink_test.go index 1d100f04e..59e49254b 100644 --- a/test/symlink_test.go +++ b/test/symlink_test.go @@ -191,8 +191,6 @@ func TestSymlinks(t *testing.T) { } fd.Close() - /* Currently fails, to be fixed with #80 - // Replace one with a directory err = os.Remove("s1/repDirLink") @@ -204,7 +202,6 @@ func TestSymlinks(t *testing.T) { if err != nil { log.Fatal(err) } - */ // Replace a file with a symlink @@ -217,8 +214,6 @@ func TestSymlinks(t *testing.T) { log.Fatal(err) } - /* Currently fails, to be fixed with #80 - // Replace a directory with a symlink err = os.RemoveAll("s1/dirToReplace") @@ -229,7 +224,6 @@ func TestSymlinks(t *testing.T) { if err != nil { log.Fatal(err) } - */ // Sync these changes and recheck From 20dee618ea59f0b248f7d455576d79fe2a575e4d Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Sat, 22 Nov 2014 02:19:16 +0000 Subject: [PATCH 2/2] Populate ignores upon adding a folder (fixes #996) --- internal/model/model.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/model/model.go b/internal/model/model.go index 73d10b604..2c4602643 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -1004,6 +1004,9 @@ func (m *Model) AddFolder(cfg config.FolderConfiguration) { m.deviceFolders[device.DeviceID] = append(m.deviceFolders[device.DeviceID], cfg.ID) } + ignores, _ := ignore.Load(filepath.Join(cfg.Path, ".stignore"), m.cfg.Options().CacheIgnoredFiles) + m.folderIgnores[cfg.ID] = ignores + m.addedFolder = true m.fmut.Unlock() }