fix: allow media downloads to shared output dirs
This commit is contained in:
parent
b4ca2e35b0
commit
40330f623b
@ -51,6 +51,7 @@
|
||||
- Messages: store forwarded-message metadata and add `--forwarded` filters for list/search. (#24 — thanks @bnvyas)
|
||||
- Doctor: report lock owner PID and distinguish paired stores locked by another process. (#105 — thanks @artemgetmann)
|
||||
- Media: recover panics per download job so one bad payload no longer drains the worker pool. (#179 — thanks @shaun0927)
|
||||
- Media: allow explicit download outputs in shared directories like `/tmp` without trying to chmod the parent directory.
|
||||
- Messages: attribute history messages from LID-addressed groups to the top-level participant sender. (#19 — thanks @entropyy0)
|
||||
- Messages: show display text for replies, reactions, and media in `messages context`. (#183 — thanks @fuleinist)
|
||||
- Send: strip a leading `+` from phone-number recipients before building WhatsApp JIDs. (#74 — thanks @FrederickStempfle)
|
||||
|
||||
@ -21,3 +21,17 @@ func EnsurePrivateDir(path string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func EnsureWritableDir(path string) error {
|
||||
if err := os.MkdirAll(path, 0o700); err != nil {
|
||||
return fmt.Errorf("create dir: %w", err)
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("stat dir: %w", err)
|
||||
}
|
||||
if !info.IsDir() {
|
||||
return fmt.Errorf("%s is not a directory", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -52,3 +52,37 @@ func TestEnsurePrivateDirRejectsFiles(t *testing.T) {
|
||||
t.Fatalf("expected error for file path")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureWritableDirDoesNotChmodExistingDir(t *testing.T) {
|
||||
dir := filepath.Join(t.TempDir(), "shared")
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
t.Fatalf("MkdirAll: %v", err)
|
||||
}
|
||||
if err := os.Chmod(dir, 0o755); err != nil {
|
||||
t.Fatalf("Chmod setup: %v", err)
|
||||
}
|
||||
if err := EnsureWritableDir(dir); err != nil {
|
||||
t.Fatalf("EnsureWritableDir: %v", err)
|
||||
}
|
||||
info, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
t.Fatalf("Stat: %v", err)
|
||||
}
|
||||
if got := info.Mode().Perm(); got != 0o755 {
|
||||
t.Fatalf("mode = %04o, want 0755", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureWritableDirCreatesPrivateDir(t *testing.T) {
|
||||
dir := filepath.Join(t.TempDir(), "new")
|
||||
if err := EnsureWritableDir(dir); err != nil {
|
||||
t.Fatalf("EnsureWritableDir: %v", err)
|
||||
}
|
||||
info, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
t.Fatalf("Stat: %v", err)
|
||||
}
|
||||
if got := info.Mode().Perm(); got != 0o700 {
|
||||
t.Fatalf("mode = %04o, want 0700", got)
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ func (c *Client) DownloadMediaToFile(ctx context.Context, directPath string, enc
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if err := fsutil.EnsurePrivateDir(filepath.Dir(targetPath)); err != nil {
|
||||
if err := fsutil.EnsureWritableDir(filepath.Dir(targetPath)); err != nil {
|
||||
return 0, fmt.Errorf("create output dir: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user