mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-08 23:08:27 +00:00
This commit is contained in:
parent
44658258d2
commit
e3cd9219b8
@ -25,11 +25,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ErrCaseConflict struct {
|
type ErrCaseConflict struct {
|
||||||
given, real string
|
Given, Real string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ErrCaseConflict) Error() string {
|
func (e *ErrCaseConflict) Error() string {
|
||||||
return fmt.Sprintf(`given name "%v" differs from name in filesystem "%v"`, e.given, e.real)
|
return fmt.Sprintf(`given name "%v" differs from name in filesystem "%v"`, e.Given, e.Real)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsErrCaseConflict(err error) bool {
|
func IsErrCaseConflict(err error) bool {
|
||||||
|
@ -1060,6 +1060,14 @@ func (f *sendReceiveFolder) handleFile(file protocol.FileInfo, snap *db.Snapshot
|
|||||||
// Check for an old temporary file which might have some blocks we could
|
// Check for an old temporary file which might have some blocks we could
|
||||||
// reuse.
|
// reuse.
|
||||||
tempBlocks, err := scanner.HashFile(f.ctx, f.fs, tempName, file.BlockSize(), nil, false)
|
tempBlocks, err := scanner.HashFile(f.ctx, f.fs, tempName, file.BlockSize(), nil, false)
|
||||||
|
if err != nil {
|
||||||
|
var caseErr *fs.ErrCaseConflict
|
||||||
|
if errors.As(err, &caseErr) {
|
||||||
|
if rerr := f.fs.Rename(caseErr.Real, tempName); rerr == nil {
|
||||||
|
tempBlocks, err = scanner.HashFile(f.ctx, f.fs, tempName, file.BlockSize(), nil, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Check for any reusable blocks in the temp file
|
// Check for any reusable blocks in the temp file
|
||||||
tempCopyBlocks, _ := blockDiff(tempBlocks, file.Blocks)
|
tempCopyBlocks, _ := blockDiff(tempBlocks, file.Blocks)
|
||||||
|
@ -1216,6 +1216,32 @@ func testPullCaseOnlyDirOrSymlink(t *testing.T, dir bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPullTempFileCaseConflict(t *testing.T) {
|
||||||
|
m, f := setupSendReceiveFolder()
|
||||||
|
defer cleanupSRFolder(f, m)
|
||||||
|
|
||||||
|
copyChan := make(chan copyBlocksState, 1)
|
||||||
|
|
||||||
|
file := protocol.FileInfo{Name: "foo"}
|
||||||
|
confl := "Foo"
|
||||||
|
tempNameConfl := fs.TempName(confl)
|
||||||
|
if fd, err := f.fs.Create(tempNameConfl); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else {
|
||||||
|
if _, err := fd.Write([]byte("data")); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
fd.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
f.handleFile(file, f.fset.Snapshot(), copyChan)
|
||||||
|
|
||||||
|
cs := <-copyChan
|
||||||
|
if _, err := cs.tempFile(); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func cleanupSharedPullerState(s *sharedPullerState) {
|
func cleanupSharedPullerState(s *sharedPullerState) {
|
||||||
s.mut.Lock()
|
s.mut.Lock()
|
||||||
defer s.mut.Unlock()
|
defer s.mut.Unlock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user