mirror of
https://github.com/rclone/rclone.git
synced 2025-08-14 07:49:00 +02:00
serve nfs: make metadata files have special file handles
Metadata files have the file handle of their source file with 0x00000001 suffixed in big endian so we can look them up directly from their file handles.
This commit is contained in:
@ -5,10 +5,13 @@ package nfs
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/object"
|
||||
"github.com/rclone/rclone/vfs"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@ -18,6 +21,8 @@ const testSymlinkCache = "go test -c && sudo setcap cap_dac_read_search+ep ./nfs
|
||||
|
||||
// Check basic CRUD operations
|
||||
func testCacheCRUD(t *testing.T, h *Handler, c Cache, fileName string) {
|
||||
isMetadata := strings.HasSuffix(fileName, ".metadata")
|
||||
|
||||
// Check reading a non existent handle returns an error
|
||||
_, _, err := c.FromHandle([]byte{10})
|
||||
assert.Error(t, err)
|
||||
@ -26,6 +31,11 @@ func testCacheCRUD(t *testing.T, h *Handler, c Cache, fileName string) {
|
||||
splitPath := []string{"dir", fileName}
|
||||
fh := c.ToHandle(h.billyFS, splitPath)
|
||||
assert.True(t, len(fh) > 0)
|
||||
if isMetadata {
|
||||
assert.Equal(t, metadataSuffix, fh[len(fh)-len(metadataSuffix):])
|
||||
} else {
|
||||
assert.NotEqual(t, metadataSuffix, fh[len(fh)-len(metadataSuffix):])
|
||||
}
|
||||
|
||||
// Read the handle back
|
||||
newFs, newSplitPath, err := c.FromHandle(fh)
|
||||
@ -43,8 +53,13 @@ func testCacheCRUD(t *testing.T, h *Handler, c Cache, fileName string) {
|
||||
|
||||
// Check the handle is gone and returning stale handle error
|
||||
_, _, err = c.FromHandle(fh)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, errStaleHandle, err)
|
||||
if !isMetadata {
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, errStaleHandle, err)
|
||||
} else {
|
||||
// Can't invalidate metadata handles
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Thrash the cache operations in parallel on different files
|
||||
@ -113,8 +128,10 @@ func TestCache(t *testing.T) {
|
||||
cacheType := cacheType
|
||||
t.Run(cacheType.String(), func(t *testing.T) {
|
||||
h := &Handler{
|
||||
vfs: vfs.New(object.MemoryFs, nil),
|
||||
billyFS: billyFS,
|
||||
}
|
||||
h.vfs.Opt.MetadataExtension = ".metadata"
|
||||
h.opt.HandleLimit = 1000
|
||||
h.opt.HandleCache = cacheType
|
||||
h.opt.HandleCacheDir = t.TempDir()
|
||||
@ -151,6 +168,10 @@ func TestCache(t *testing.T) {
|
||||
t.Run("ThrashSame", func(t *testing.T) {
|
||||
testCacheThrashSame(t, h, c)
|
||||
})
|
||||
// Metadata file handles only supported on non memory
|
||||
t.Run("CRUDMetadata", func(t *testing.T) {
|
||||
testCacheCRUD(t, h, c, "file.metadata")
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user