"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
lib/http: prefix links in directory listings with ./ so selfupdate works
Nick Craig-Wood89521d875d59
diff --git a/cmd/serve/http/testdata/golden/index.html b/cmd/serve/http/testdata/golden/index.htmlindex 2ddb71e39..31c2af4aa 100644--- a/cmd/serve/http/testdata/golden/index.html+++ b/cmd/serve/http/testdata/golden/index.html@@ -6,8 +6,8 @@</head><body><h1>Directory listing of /</h1>-<a href="three/">three/</a><br />-<a href="one%25.txt">one%.txt</a><br />-<a href="two.txt">two.txt</a><br />+<a href="./three/">three/</a><br />+<a href="./one%25.txt">one%.txt</a><br />+<a href="./two.txt">two.txt</a><br /></body></html>diff --git a/cmd/serve/http/testdata/golden/three.html b/cmd/serve/http/testdata/golden/three.htmlindex 85ea95184..f97b72bf9 100644--- a/cmd/serve/http/testdata/golden/three.html+++ b/cmd/serve/http/testdata/golden/three.html@@ -6,7 +6,7 @@</head><body><h1>Directory listing of /three</h1>-<a href="a.txt">a.txt</a><br />-<a href="b.txt">b.txt</a><br />+<a href="./a.txt">a.txt</a><br />+<a href="./b.txt">b.txt</a><br /></body></html>diff --git a/cmd/serve/webdav/testdata/golden/index.html b/cmd/serve/webdav/testdata/golden/index.htmlindex 2ddb71e39..31c2af4aa 100644--- a/cmd/serve/webdav/testdata/golden/index.html+++ b/cmd/serve/webdav/testdata/golden/index.html@@ -6,8 +6,8 @@</head><body><h1>Directory listing of /</h1>-<a href="three/">three/</a><br />-<a href="one%25.txt">one%.txt</a><br />-<a href="two.txt">two.txt</a><br />+<a href="./three/">three/</a><br />+<a href="./one%25.txt">one%.txt</a><br />+<a href="./two.txt">two.txt</a><br /></body></html>diff --git a/cmd/serve/webdav/testdata/golden/three.html b/cmd/serve/webdav/testdata/golden/three.htmlindex 85ea95184..f97b72bf9 100644--- a/cmd/serve/webdav/testdata/golden/three.html+++ b/cmd/serve/webdav/testdata/golden/three.html@@ -6,7 +6,7 @@</head><body><h1>Directory listing of /three</h1>-<a href="a.txt">a.txt</a><br />-<a href="b.txt">b.txt</a><br />+<a href="./a.txt">a.txt</a><br />+<a href="./b.txt">b.txt</a><br /></body></html>diff --git a/fs/operations/index_test.go b/fs/operations/index_test.goindex cf8a1b117..56e057e03 100644--- a/fs/operations/index_test.go+++ b/fs/operations/index_test.go@@ -121,16 +121,16 @@ func TestIndex(t *testing.T) {assert.Equal(t, `[{"name":"sub/","size":4096,"url":"./sub/","mod_time":"0001-01-01T00:00:00Z","mode":2147484141,"is_dir":true,"is_symlink":false},{"name":"file1.txt","size":5,"url":"./file1.txt","mod_time":"0001-01-01T00:00:00Z","mode":420,"is_dir":false,"is_symlink":false}]`, r.read(t, "caddy.json"))html := r.read(t, "index.html")- assert.Contains(t, html, `<a href="sub/">sub/</a>`)- assert.Contains(t, html, `<a href="file1.txt">file1.txt</a>`)+ assert.Contains(t, html, `<a href="./sub/">sub/</a>`)+ assert.Contains(t, html, `<a href="./file1.txt">file1.txt</a>`)assert.NotContains(t, html, "Go up")assert.Contains(t, html, "sortBy")assert.NotContains(t, html, "download=zip")// The listings never show the outputs and link up below the roothtml = r.read(t, "sub/index.html")- assert.Contains(t, html, `<a href="deep/">deep/</a>`)- assert.Contains(t, html, `<a href="file2.txt">file2.txt</a>`)+ assert.Contains(t, html, `<a href="./deep/">deep/</a>`)+ assert.Contains(t, html, `<a href="./file2.txt">file2.txt</a>`)assert.NotContains(t, html, "index.html")assert.Contains(t, html, "Go up")@@ -219,7 +219,7 @@ func TestIndexFilter(t *testing.T) {assert.NotContains(t, r.read(t, "sub/index.html"), "deep/")other := r.read(t, "other/index.html")assert.NotContains(t, other, "notes.md")- assert.Contains(t, r.read(t, "index.html"), `<a href="other/">other/</a>`)+ assert.Contains(t, r.read(t, "index.html"), `<a href="./other/">other/</a>`)// A second run changes nothing, in particular it doesn't delete// other/index.html even though other/ has no visible content@@ -238,7 +238,7 @@ func TestIndexRules(t *testing.T) {r.index(t)r.checkFiles(t, "file1.txt", "index.html", "sub/file2.txt", "sub/index.html", "sub/deep/file3.txt", "sub/deep/index.html")assert.Equal(t, "hand written", r.read(t, "sub/deep/index.html"))- assert.Contains(t, r.read(t, "sub/index.html"), `<a href="deep/">deep/</a>`)+ assert.Contains(t, r.read(t, "sub/index.html"), `<a href="./deep/">deep/</a>`)// Include rules imply excluding everything elser.opt.Rules = filter.RulesOpt{IncludeRule: []string{"/sub/**"}}@@ -256,16 +256,16 @@ func TestIndexMaxDepth(t *testing.T) {r.opt.MaxDepth = 1r.index(t)r.checkFiles(t, "file1.txt", "index.html", "sub/file2.txt", "sub/deep/file3.txt")- assert.Contains(t, r.read(t, "index.html"), `<a href="sub/">sub/</a>`)+ assert.Contains(t, r.read(t, "index.html"), `<a href="./sub/">sub/</a>`)}func TestIndexLinkIndex(t *testing.T) {r := newIndexRun(t)r.opt.LinkIndex = truer.index(t)- assert.Contains(t, r.read(t, "index.html"), `<a href="sub/index.html">sub/</a>`)+ assert.Contains(t, r.read(t, "index.html"), `<a href="./sub/index.html">sub/</a>`)html := r.read(t, "sub/index.html")- assert.Contains(t, html, `<a href="deep/index.html">deep/</a>`)+ assert.Contains(t, html, `<a href="./deep/index.html">deep/</a>`)assert.Contains(t, html, `<a href="../index.html">`)}@@ -408,7 +408,7 @@ func TestIndexChanged(t *testing.T) {r.opt.Changed = []string{"sub/new/file5.txt"}transfers, _ = r.index(t)assert.Equal(t, int64(2), transfers)- assert.Contains(t, r.read(t, "sub/index.html"), `<a href="new/">new/</a>`)+ assert.Contains(t, r.read(t, "sub/index.html"), `<a href="./new/">new/</a>`)assert.Contains(t, r.read(t, "sub/new/index.html"), "file5.txt")// A changed directory is walked whether or not it has a trailing slashdiff --git a/fs/rc/rcserver/rcserver_test.go b/fs/rc/rcserver/rcserver_test.goindex 1a5a67ffa..16ace6d10 100644--- a/fs/rc/rcserver/rcserver_test.go+++ b/fs/rc/rcserver/rcserver_test.go@@ -266,9 +266,9 @@ func TestRemoteServing(t *testing.T) {</head><body><h1>Directory listing of /</h1>-<a href="dir/">dir/</a><br />-<a href="modtime/">modtime/</a><br />-<a href="file.txt">file.txt</a><br />+<a href="./dir/">dir/</a><br />+<a href="./modtime/">modtime/</a><br />+<a href="./file.txt">file.txt</a><br /></body></html>`,@@ -317,7 +317,7 @@ func TestRemoteServing(t *testing.T) {</head><body><h1>Directory listing of /dir</h1>-<a href="file2.txt">file2.txt</a><br />+<a href="./file2.txt">file2.txt</a><br /></body></html>`,diff --git a/lib/http/serve/dir.go b/lib/http/serve/dir.goindex ce409d6ae..2d511373d 100644--- a/lib/http/serve/dir.go+++ b/lib/http/serve/dir.go@@ -158,6 +158,12 @@ func (d *Directory) AddHTMLEntry(remote string, isDir bool, size int64, modTimeleaf = ""}urlRemote := leaf+ if leaf != "" {+ // Link with a leading ./ as Caddy's file server does, since+ // released versions of rclone selfupdate look for+ // href="./vX.Y.Z/" in the listing of downloads.rclone.org+ urlRemote = "./" + leaf+ }mimeType := fs.MimeTypeFromName(leaf)linkIndex, zipURL := "", ""if isDir {diff --git a/lib/http/serve/dir_test.go b/lib/http/serve/dir_test.goindex ea5c5fe5d..8adef5e9d 100644--- a/lib/http/serve/dir_test.go+++ b/lib/http/serve/dir_test.go@@ -48,10 +48,10 @@ func TestAddHTMLEntry(t *testing.T) {d.AddHTMLEntry("\"quotes\".txt", false, 64, modtime)assert.Equal(t, []DirEntry{{remote: "", URL: "/", ZipURL: "/?download=zip", Leaf: "/", IsDir: true, Size: 0, ModTime: modtime, MimeType: "inode/directory"},- {remote: "dir", URL: "dir/", ZipURL: "dir/?download=zip", Leaf: "dir/", IsDir: true, Size: 0, ModTime: modtime, MimeType: "inode/directory"},- {remote: "a/b/c/d.txt", URL: "d.txt", ZipURL: "", Leaf: "d.txt", IsDir: false, Size: 64, ModTime: modtime, MimeType: "text/plain; charset=utf-8"},+ {remote: "dir", URL: "./dir/", ZipURL: "./dir/?download=zip", Leaf: "dir/", IsDir: true, Size: 0, ModTime: modtime, MimeType: "inode/directory"},+ {remote: "a/b/c/d.txt", URL: "./d.txt", ZipURL: "", Leaf: "d.txt", IsDir: false, Size: 64, ModTime: modtime, MimeType: "text/plain; charset=utf-8"},{remote: "a/b/c/colon:colon.txt", URL: "./colon:colon.txt", ZipURL: "", Leaf: "colon:colon.txt", IsDir: false, Size: 64, ModTime: modtime, MimeType: "text/plain; charset=utf-8"},- {remote: "\"quotes\".txt", URL: "%22quotes%22.txt", ZipURL: "", Leaf: "\"quotes\".txt", Size: 64, IsDir: false, ModTime: modtime, MimeType: "text/plain; charset=utf-8"},+ {remote: "\"quotes\".txt", URL: "./%22quotes%22.txt", ZipURL: "", Leaf: "\"quotes\".txt", Size: 64, IsDir: false, ModTime: modtime, MimeType: "text/plain; charset=utf-8"},}, d.Entries)// Now test with a query parameter@@ -59,8 +59,8 @@ func TestAddHTMLEntry(t *testing.T) {d.AddHTMLEntry("file", false, 64, modtime)d.AddHTMLEntry("dir", true, 0, modtime)assert.Equal(t, []DirEntry{- {remote: "file", URL: "file?potato=42", ZipURL: "", Leaf: "file", IsDir: false, Size: 64, ModTime: modtime, MimeType: "application/octet-stream"},- {remote: "dir", URL: "dir/?potato=42", ZipURL: "dir/?download=zip", Leaf: "dir/", IsDir: true, Size: 0, ModTime: modtime, MimeType: "inode/directory"},+ {remote: "file", URL: "./file?potato=42", ZipURL: "", Leaf: "file", IsDir: false, Size: 64, ModTime: modtime, MimeType: "application/octet-stream"},+ {remote: "dir", URL: "./dir/?potato=42", ZipURL: "./dir/?download=zip", Leaf: "dir/", IsDir: true, Size: 0, ModTime: modtime, MimeType: "inode/directory"},}, d.Entries)// Now test with a link index@@ -68,8 +68,8 @@ func TestAddHTMLEntry(t *testing.T) {d.AddHTMLEntry("file", false, 64, modtime)d.AddHTMLEntry("dir", true, 0, modtime)assert.Equal(t, []DirEntry{- {remote: "file", URL: "file", ZipURL: "", Leaf: "file", IsDir: false, Size: 64, ModTime: modtime, MimeType: "application/octet-stream"},- {remote: "dir", URL: "dir/index.html", ZipURL: "dir/?download=zip", Leaf: "dir/", IsDir: true, Size: 0, ModTime: modtime, MimeType: "inode/directory"},+ {remote: "file", URL: "./file", ZipURL: "", Leaf: "file", IsDir: false, Size: 64, ModTime: modtime, MimeType: "application/octet-stream"},+ {remote: "dir", URL: "./dir/index.html", ZipURL: "./dir/?download=zip", Leaf: "dir/", IsDir: true, Size: 0, ModTime: modtime, MimeType: "inode/directory"},}, d.Entries)assert.Equal(t, []Crumb{{Link: "../index.html", Text: "/"}, {Link: "index.html", Text: "z"}}, d.Breadcrumb)assert.Equal(t, "../index.html", d.UpLink())diff --git a/lib/http/templates/caddy.json b/lib/http/templates/caddy.jsonindex 965f166cb..32e8bb90b 100644--- a/lib/http/templates/caddy.json+++ b/lib/http/templates/caddy.json@@ -1 +1 @@-[{{range $i, $e := .Entries}}{{if $i}},{{end}}{"name":{{json $e.Leaf}},"size":{{if $e.IsDir}}4096{{else}}{{$e.Size}}{{end}},"url":{{if hasPrefix $e.URL "./"}}{{json $e.URL}}{{else}}{{json (print "./" $e.URL)}}{{end}},"mod_time":{{json $e.ModTime}},"mode":{{if $e.IsDir}}2147484141{{else}}420{{end}},"is_dir":{{$e.IsDir}},"is_symlink":false}{{end}}]+[{{range $i, $e := .Entries}}{{if $i}},{{end}}{"name":{{json $e.Leaf}},"size":{{if $e.IsDir}}4096{{else}}{{$e.Size}}{{end}},"url":{{json $e.URL}},"mod_time":{{json $e.ModTime}},"mode":{{if $e.IsDir}}2147484141{{else}}420{{end}},"is_dir":{{$e.IsDir}},"is_symlink":false}{{end}}]