From ffd11662babcf0a2d2562ba104a4276ac8b47fd2 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 31 Jul 2018 11:22:45 +0100 Subject: [PATCH] cache: fix nil pointer deref when using lsjson on cached directory This stops embedding the fs.Directory into the cache.Directory because it can be nil and implements an ID method which checks the nil status. See: https://forum.rclone.org/t/runtime-error-with-cache-remote-and-lsjson/6305 --- backend/cache/directory.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/cache/directory.go b/backend/cache/directory.go index 658dbda72..863612758 100644 --- a/backend/cache/directory.go +++ b/backend/cache/directory.go @@ -12,7 +12,7 @@ import ( // Directory is a generic dir that stores basic information about it type Directory struct { - fs.Directory `json:"-"` + Directory fs.Directory `json:"-"` // can be nil CacheFs *Fs `json:"-"` // cache fs Name string `json:"name"` // name of the directory @@ -125,6 +125,14 @@ func (d *Directory) Items() int64 { return d.CacheItems } +// ID returns the ID of the cached directory if known +func (d *Directory) ID() string { + if d.Directory == nil { + return "" + } + return d.Directory.ID() +} + var ( _ fs.Directory = (*Directory)(nil) )