Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Long filenames #20

@jcwinsor

Description

@jcwinsor

I encountered some creator pages where images patreon-dl tries to download have a very long name, presumably auto-generated previews of something. If they are too long for the underlying filesystem, os.Create in DownloadWorker fails and causes an error to be printed down the road.

As a workaround, I hashed filenames over 255 characters (cf. this summary of max filename lengths) in my local copy:

--- a/DownloadManager.go
+++ b/DownloadManager.go
@@ -12,6 +12,8 @@ import (
        "strconv"
        "strings"
        "time"
+       "golang.org/x/crypto/sha3"
+       "encoding/hex"
 )
 
 var downloadDir string = "images"
@@ -87,7 +89,13 @@ func DownloadWorker(id int, jobs <-chan []string, resultCh chan<- *result, bar *
                defer resp.Body.Close()
 
                // Create the file
-               out, err := os.Create(filepath.Join(".", downloadDir, path.Base(strPath)))
+               basepath := path.Base(strPath)
+               if len(basepath) > 255 {
+                       h_basepath := sha3.New512()
+                       h_basepath.Write([]byte(basepath))
+                       basepath = hex.EncodeToString(h_basepath.Sum(nil))
+               }
+               out, err := os.Create(filepath.Join(".", downloadDir, basepath))
                if err != nil {
                        return &result{err: err}
                }

Not saying this is ideal, it's merely included as an idea.

I also wanted to thank you for writing this! Works really well, overall 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions