diff --git a/weed/command/filer_remote_sync_dir.go b/weed/command/filer_remote_sync_dir.go index e22ddbf15b..0636590716 100644 --- a/weed/command/filer_remote_sync_dir.go +++ b/weed/command/filer_remote_sync_dir.go @@ -243,9 +243,9 @@ func processCreateEvent( return nil } // A create reshaped from a rename into the mount (mustSend) writes an empty - // entry as a zero-byte object; a remote-only entry holds nothing local to - // send and still skips. - if !filer.HasData(message.NewEntry) && !(mustSend && !isRemoteOnly(message.NewEntry)) { + // entry as a zero-byte object; a dropped local copy whose remote object + // still describes it holds nothing local to send and still skips. + if !filer.HasData(message.NewEntry) && !(mustSend && !isDroppedLocalCopy(message.NewEntry)) { return nil } glog.V(2).Infof("create: %+v", resp) diff --git a/weed/command/filer_remote_sync_dir_test.go b/weed/command/filer_remote_sync_dir_test.go index 66b780223b..9b6121f6a3 100644 --- a/weed/command/filer_remote_sync_dir_test.go +++ b/weed/command/filer_remote_sync_dir_test.go @@ -2216,6 +2216,29 @@ func TestRenameIntoMountWritesAnEmptyFile(t *testing.T) { } }) + // A stale stamp is not a dropped copy: truncating a synced file drops its + // chunks and changes FileSize, but leaves the RemoteEntry behind, so + // isRemoteOnly alone would skip the create and the truncated content would + // never reach the new key. + t.Run("a stale-stamped entry uploads its truncated content", func(t *testing.T) { + stamp := &filer_pb.RemoteEntry{StorageName: "b2", RemoteETag: "abc", RemoteSize: 7, RemoteMtime: 1786096669, LastLocalSyncTsNs: 1786096669*1e9 + 1} + entry := &filer_pb.Entry{Name: "empty.txt", Attributes: &filer_pb.FuseAttributes{Mtime: 1786096669, FileSize: 0}, RemoteEntry: stamp} + if !isRemoteOnly(entry) { + t.Fatal("precondition: the stale stamp still reads remote-only") + } + if isDroppedLocalCopy(entry) { + t.Fatal("precondition: the stale object does not describe the entry") + } + remote := &recordingRemote{} + filerClient := &stubFilerClient{entry: entry} + if err := processCreateEvent(filerClient, filerClient, "", remote, mountedDir, mountLoc, renameIn(entry), true); err != nil { + t.Fatal(err) + } + if len(remote.writes) != 1 || !proto.Equal(remote.writes[0], wantWrite) { + t.Errorf("writes = %+v, want the new key %s written", remote.writes, remote_storage.FormatLocation(wantWrite)) + } + }) + // an ordinary create of an empty entry is unchanged: no object t.Run("a plain empty create still writes nothing", func(t *testing.T) { entry := &filer_pb.Entry{Name: "empty.txt", Attributes: &filer_pb.FuseAttributes{Mtime: 1786096669}}