mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 15:43:21 +00:00
Ignore unexpected files in intermediate directories
Listing the data/ folder in a repository no longer fails if it contains files in the data/ folder. This also ignore .DS_Store files created by macOS.
This commit is contained in:
parent
11c5a548e8
commit
22a6412b81
3 changed files with 43 additions and 0 deletions
9
changelog/unreleased/issue-219
Normal file
9
changelog/unreleased/issue-219
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Bugfix: Ignore unexpected files in the data/ folder
|
||||||
|
|
||||||
|
If the data folder of a repository contained files, this would prevent restic
|
||||||
|
from retrieving a list of file data files. This has been fixed. As a workaround
|
||||||
|
remove the files that are directly contained in the data folder (e.g.,
|
||||||
|
`.DS_Store` files).
|
||||||
|
|
||||||
|
https://github.com/restic/rest-server/issues/219
|
||||||
|
https://github.com/restic/rest-server/pull/221
|
|
@ -379,6 +379,32 @@ func TestResticErrorHandler(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestListWithUnexpectedFiles(t *testing.T) {
|
||||||
|
mux, _, _, tempdir, cleanup := createTestHandler(t, Server{
|
||||||
|
AppendOnly: true,
|
||||||
|
NoAuth: true,
|
||||||
|
Debug: true,
|
||||||
|
})
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
// create the repo
|
||||||
|
checkRequest(t, mux.ServeHTTP,
|
||||||
|
newRequest(t, "POST", "/?create=true", nil),
|
||||||
|
[]wantFunc{wantCode(http.StatusOK)})
|
||||||
|
err := os.WriteFile(path.Join(tempdir, "data", "temp"), []byte{}, 0o666)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("creating unexpected file failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 1; i <= 2; i++ {
|
||||||
|
req := newRequest(t, "GET", "/data/", nil)
|
||||||
|
req.Header.Set("Accept", "application/vnd.x.restic.rest.v2")
|
||||||
|
|
||||||
|
checkRequest(t, mux.ServeHTTP, req,
|
||||||
|
[]wantFunc{wantCode(http.StatusOK)})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSplitURLPath(t *testing.T) {
|
func TestSplitURLPath(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
// Params
|
// Params
|
||||||
|
|
|
@ -379,6 +379,10 @@ func (h *Handler) listBlobsV1(w http.ResponseWriter, r *http.Request) {
|
||||||
var names []string
|
var names []string
|
||||||
for _, i := range items {
|
for _, i := range items {
|
||||||
if isHashed(objectType) {
|
if isHashed(objectType) {
|
||||||
|
if !i.IsDir() {
|
||||||
|
// ignore files in intermediate directories
|
||||||
|
continue
|
||||||
|
}
|
||||||
subpath := filepath.Join(path, i.Name())
|
subpath := filepath.Join(path, i.Name())
|
||||||
var subitems []os.FileInfo
|
var subitems []os.FileInfo
|
||||||
subitems, err = ioutil.ReadDir(subpath)
|
subitems, err = ioutil.ReadDir(subpath)
|
||||||
|
@ -434,6 +438,10 @@ func (h *Handler) listBlobsV2(w http.ResponseWriter, r *http.Request) {
|
||||||
var blobs []Blob
|
var blobs []Blob
|
||||||
for _, i := range items {
|
for _, i := range items {
|
||||||
if isHashed(objectType) {
|
if isHashed(objectType) {
|
||||||
|
if !i.IsDir() {
|
||||||
|
// ignore files in intermediate directories
|
||||||
|
continue
|
||||||
|
}
|
||||||
subpath := filepath.Join(path, i.Name())
|
subpath := filepath.Join(path, i.Name())
|
||||||
var subitems []os.FileInfo
|
var subitems []os.FileInfo
|
||||||
subitems, err = ioutil.ReadDir(subpath)
|
subitems, err = ioutil.ReadDir(subpath)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue