mirror of
https://github.com/rclone/rclone
synced 2024-11-16 16:15:34 +01:00
compress: fix ChangeNotify
ChangeNotify has been broken on the compress backend for a long time! Before this change it was wrapping the file names received rather than unwrapping them to discover the original names. It is likely ChangeNotify was working adequately though for users as the VFS just uses the directories rather than the file names.
This commit is contained in:
parent
bd23ea028e
commit
3ea1c5c4d2
@ -257,6 +257,16 @@ func isMetadataFile(filename string) bool {
|
|||||||
return strings.HasSuffix(filename, metaFileExt)
|
return strings.HasSuffix(filename, metaFileExt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks whether a file is a metadata file and returns the original
|
||||||
|
// file name and a flag indicating whether it was a metadata file or
|
||||||
|
// not.
|
||||||
|
func unwrapMetadataFile(filename string) (string, bool) {
|
||||||
|
if !isMetadataFile(filename) {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return filename[:len(filename)-len(metaFileExt)], true
|
||||||
|
}
|
||||||
|
|
||||||
// makeDataName generates the file name for a data file with specified compression mode
|
// makeDataName generates the file name for a data file with specified compression mode
|
||||||
func makeDataName(remote string, size int64, mode int) (newRemote string) {
|
func makeDataName(remote string, size int64, mode int) (newRemote string) {
|
||||||
if mode != Uncompressed {
|
if mode != Uncompressed {
|
||||||
@ -979,7 +989,8 @@ func (f *Fs) ChangeNotify(ctx context.Context, notifyFunc func(string, fs.EntryT
|
|||||||
wrappedNotifyFunc := func(path string, entryType fs.EntryType) {
|
wrappedNotifyFunc := func(path string, entryType fs.EntryType) {
|
||||||
fs.Logf(f, "path %q entryType %d", path, entryType)
|
fs.Logf(f, "path %q entryType %d", path, entryType)
|
||||||
var (
|
var (
|
||||||
wrappedPath string
|
wrappedPath string
|
||||||
|
isMetadataFile bool
|
||||||
)
|
)
|
||||||
switch entryType {
|
switch entryType {
|
||||||
case fs.EntryDirectory:
|
case fs.EntryDirectory:
|
||||||
@ -987,7 +998,10 @@ func (f *Fs) ChangeNotify(ctx context.Context, notifyFunc func(string, fs.EntryT
|
|||||||
case fs.EntryObject:
|
case fs.EntryObject:
|
||||||
// Note: All we really need to do to monitor the object is to check whether the metadata changed,
|
// Note: All we really need to do to monitor the object is to check whether the metadata changed,
|
||||||
// as the metadata contains the hash. This will work unless there's a hash collision and the sizes stay the same.
|
// as the metadata contains the hash. This will work unless there's a hash collision and the sizes stay the same.
|
||||||
wrappedPath = makeMetadataName(path)
|
wrappedPath, isMetadataFile = unwrapMetadataFile(path)
|
||||||
|
if !isMetadataFile {
|
||||||
|
return
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
fs.Errorf(path, "press ChangeNotify: ignoring unknown EntryType %d", entryType)
|
fs.Errorf(path, "press ChangeNotify: ignoring unknown EntryType %d", entryType)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user