refactor: unify data directory structure
Unify user data directory from fragmented layout to consistent nested format: - Move WebDAV from: data/files/<username> → data/<username>/files/ - Move CalDAV from: data/<username>/cal-<name> → data/<username>/calendars/<name> - Move CardDAV from: data/<username>/card-<name> → data/<username>/addressbooks/<name> Changes: - internal/store/store.go: Update collectionPath() to map collection names - internal/store/migrate.go: Add idempotent Migrate() method - internal/store/migrate_test.go: Comprehensive migration tests - internal/webdav/handler.go: Use new unified path structure - cmd/server/main.go: Auto-run migration on startup - tools/nidusctl/main.go: Add migrate subcommand - Update tests to verify new structure URL endpoints unchanged - only on-disk structure modified. All tests pass.
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
// NewHandler returns an http.Handler that provides standard WebDAV file access,
|
||||
// mounted at the fixed URL /files/ for every user and rooted at
|
||||
// dataDir/files/<username>/ on disk. The URL is the same for all users —
|
||||
// dataDir/<username>/files on disk. The URL is the same for all users —
|
||||
// which user's directory is served is resolved from the Basic Auth identity
|
||||
// in the request context, not from the URL.
|
||||
//
|
||||
@@ -38,7 +38,7 @@ func NewHandler(cfg *config.Config, dataDir string, logger *slog.Logger) http.Ha
|
||||
h, ok := handlers[p.Username]
|
||||
if !ok {
|
||||
username := p.Username
|
||||
userDir := filepath.Join(dataDir, "files", username)
|
||||
userDir := filepath.Join(dataDir, username, "files")
|
||||
if err := os.MkdirAll(userDir, 0o755); err != nil {
|
||||
mu.Unlock()
|
||||
logger.Error("creating user WebDAV dir", "user", username, "error", err)
|
||||
|
||||
@@ -54,10 +54,10 @@ func TestPerUserIsolationAndPrefix(t *testing.T) {
|
||||
t.Fatalf("expected bob to get 404 for alice's file, got %d", bobRec.Code)
|
||||
}
|
||||
|
||||
// Confirm the file physically landed under dataDir/files/alice/, not
|
||||
// Confirm the file physically landed under dataDir/alice/files/, not
|
||||
// nested under an extra files/files/... path.
|
||||
if _, err := os.Stat(dir + "/files/alice/note.txt"); err != nil {
|
||||
t.Fatalf("expected file at dataDir/files/alice/note.txt: %v", err)
|
||||
if _, err := os.Stat(dir + "/alice/files/note.txt"); err != nil {
|
||||
t.Fatalf("expected file at dataDir/alice/files/note.txt: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user