fix(platform): normalize native paths for storage and backup validation
This commit is contained in:
1 parent
bea53ce3c8
commit
1a8f70ca13
9 files changed
+120
-8
No files matched your search
@@ -192,13 +192,21 @@ func backupResourceError(err error) error {
|
||||
func (s *Server) validateResources(stage string) error {
|
||||
temp := &Server{FontsDir: filepath.Join(stage, "app", "fonts"), ThemesDir: filepath.Join(stage, "app", "themes"), PluginsDir: filepath.Join(stage, "app", "plugins")}
|
||||
for _, kind := range []string{"fonts", "themes", "plugins"} {
|
||||
entries, err := os.ReadDir(filepath.Join(stage, "app", kind))
|
||||
resourceDir := filepath.Join(stage, "app", kind)
|
||||
info, err := os.Stat(resourceDir)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return backupResourceError(err)
|
||||
}
|
||||
if !info.IsDir() {
|
||||
return i18n.New("w_the_resource_directory_contains_3898a5", errMaintenanceInput)
|
||||
}
|
||||
entries, err := os.ReadDir(resourceDir)
|
||||
if err != nil {
|
||||
return backupResourceError(err)
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if !entry.IsDir() {
|
||||
return i18n.New("w_the_resource_directory_contains_3898a5", errMaintenanceInput)
|
||||
|
||||
@@ -54,7 +54,11 @@ func scanStorage(ctx context.Context, dataDir, vaultDir string) (storageUsage, e
|
||||
if err != nil {
|
||||
return usage, err
|
||||
}
|
||||
vaultRoot, err := filepath.Abs(vaultDir)
|
||||
vaultRoot, err := filepath.EvalSymlinks(vaultDir)
|
||||
if err != nil {
|
||||
return usage, err
|
||||
}
|
||||
vaultRoot, err = filepath.Abs(vaultRoot)
|
||||
if err != nil {
|
||||
return usage, err
|
||||
}
|
||||
|
||||
@@ -112,3 +112,34 @@ func TestStorageIncludesOptionalAndImportedFontBytes(t *testing.T) {
|
||||
t.Fatal("分类与总量不一致")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStorageResolvesBothRootAliases(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
data := filepath.Join(root, "data")
|
||||
vault := filepath.Join(data, "vault")
|
||||
if err := os.MkdirAll(vault, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(vault, "note.md"), []byte("content"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(data, "other.bin"), []byte("misc"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
alias := filepath.Join(t.TempDir(), "alias")
|
||||
if err := os.Symlink(root, alias); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, roots := range [][2]string{
|
||||
{data, filepath.Join(alias, "data", "vault")},
|
||||
{filepath.Join(alias, "data"), vault},
|
||||
} {
|
||||
usage, err := scanStorage(context.Background(), roots[0], roots[1])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if usage.TotalSize != 11 || usage.Categories[0].Size != 7 || usage.Categories[5].Size != 4 {
|
||||
t.Fatalf("root aliases counted more than once: %+v", usage)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user