Skip to content
Open
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
11 changes: 7 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ func loadFiles() (clipboard clipboard, err error) {
}

func saveFiles(clipboard clipboard) error {
for _, path := range clipboard.paths {
// the clipboard file stores one path per line so a newline cannot be saved
if strings.ContainsAny(path, "\n\r") {
return fmt.Errorf("cannot copy %s because the name contains a newline", path)
}
}

if err := os.MkdirAll(filepath.Dir(gFilesPath), 0o700); err != nil {
return fmt.Errorf("creating data directory: %w", err)
}
Expand All @@ -183,10 +190,6 @@ func saveFiles(clipboard clipboard) error {
}

for _, path := range clipboard.paths {
if strings.ContainsAny(path, "\n\r") {
log.Printf("clipboard: skipping path with newline: %q", path)
continue
}
if _, err := fmt.Fprintln(files, path); err != nil {
return fmt.Errorf("write path to file: %w", err)
}
Expand Down
Loading