diff --git a/hostinger/archive.go b/hostinger/archive.go index 9e28778797..1770b76c51 100644 --- a/hostinger/archive.go +++ b/hostinger/archive.go @@ -37,7 +37,7 @@ func AlgoToExtension(algo string) (string, error) { } } -func Unarchive(ctx context.Context, src, dst string, afs afero.Fs, overwrite bool) error { +func Unarchive(ctx context.Context, src, dst string, afs afero.Fs, overwrite bool, dirMode fs.FileMode) error { reader, err := afs.Open(src) if err != nil { return fmt.Errorf("archive open: %w", err) @@ -61,7 +61,7 @@ func Unarchive(ctx context.Context, src, dst string, afs afero.Fs, overwrite boo return fbErrors.ErrExist } - if err := afs.MkdirAll(filepath.Dir(fullpath), fs.ModeDir); err != nil { + if err := afs.MkdirAll(filepath.Dir(fullpath), dirMode); err != nil { return fmt.Errorf("extract mkdir: %w", err) } @@ -98,7 +98,7 @@ func Unarchive(ctx context.Context, src, dst string, afs afero.Fs, overwrite boo return fbErrors.ErrInvalidDataType } -func Archive(ctx context.Context, afs afero.Fs, archive, algo string, filenames []string) error { +func Archive(ctx context.Context, afs afero.Fs, archive, algo string, filenames []string, dirMode fs.FileMode) error { extension, err := AlgoToExtension(algo) if err != nil { return fbErrors.ErrInvalidRequestParams @@ -120,8 +120,7 @@ func Archive(ctx context.Context, afs afero.Fs, archive, algo string, filenames return fbErrors.ErrExist } - err = afs.MkdirAll(filepath.Dir(archive), fs.ModeDir) - if err != nil { + if err := afs.MkdirAll(filepath.Dir(archive), dirMode); err != nil { return err } diff --git a/hostinger/archive_test.go b/hostinger/archive_test.go index 578058e20a..9a2b474f99 100644 --- a/hostinger/archive_test.go +++ b/hostinger/archive_test.go @@ -83,7 +83,7 @@ func TestArchive(t *testing.T) { archivePath := "/out/archive" filenames := []string{"/data/a.txt", "/data/b.txt"} - if err := Archive(context.Background(), fs, archivePath, "zip", filenames); err != nil { + if err := Archive(context.Background(), fs, archivePath, "zip", filenames, 0755); err != nil { t.Fatalf("Archive failed: %v", err) } @@ -109,12 +109,12 @@ func TestUnarchive(t *testing.T) { archivePath := "/archive" filenames := []string{"/data/a.txt", "/data/b.txt", "/data/subdir"} - if err := Archive(context.Background(), fs, archivePath, "zip", filenames); err != nil { + if err := Archive(context.Background(), fs, archivePath, "zip", filenames, 0755); err != nil { t.Fatalf("Archive failed: %v", err) } destDir := "/extracted" - if err := Unarchive(context.Background(), archivePath+".zip", destDir, fs, true); err != nil { + if err := Unarchive(context.Background(), archivePath+".zip", destDir, fs, true, 0755); err != nil { t.Fatalf("Unarchive failed: %v", err) } diff --git a/http/resource.go b/http/resource.go index 25a1e9acb8..377d3d3510 100644 --- a/http/resource.go +++ b/http/resource.go @@ -345,7 +345,7 @@ func resourcePatchHandler(fileCache FileCache) handleFunc { return fberrors.ErrPermissionDenied } - return hostinger.Unarchive(r.Context(), src, dst, d.user.Fs, override) + return hostinger.Unarchive(r.Context(), src, dst, d.user.Fs, override, d.settings.DirMode) } return patchAction(r.Context(), action, src, dst, d, fileCache) }, action, src, dst, d.user) @@ -552,7 +552,7 @@ func archiveHandler(r *http.Request, d *data) error { return fberrors.ErrInvalidRequestParams } - return hostinger.Archive(r.Context(), d.user.Fs, archive, algo, filenames) + return hostinger.Archive(r.Context(), d.user.Fs, archive, algo, filenames, d.settings.DirMode) } func chmodActionHandler(r *http.Request, d *data) error {