Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions hostinger/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions hostinger/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions http/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down