From 0e78c2307da4177fa49031e717c3688d21428695 Mon Sep 17 00:00:00 2001 From: clsr Date: Tue, 28 Jun 2016 20:00:06 +0200 Subject: Remove storage folder path collisions for short IDs --- USAGE | 2 +- storage.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/USAGE b/USAGE index bd48ed8..3fea3fa 100644 --- a/USAGE +++ b/USAGE @@ -54,7 +54,7 @@ Running example: --name Example --id-charset CHARSET - sets the charset for file IDs in URLs to CHARSET; should only include URL-safe characters and no slashes or underscores + sets the charset for file IDs in URLs to CHARSET; should only include URL-safe characters and no slashes example: --id-charset 0123456789 --id-length LENGTH diff --git a/storage.go b/storage.go index f33dc34..b20c189 100644 --- a/storage.go +++ b/storage.go @@ -153,10 +153,11 @@ func (s *Storage) randomId() string { } func (s *Storage) idToFolder(subfolder, id string) string { - for len(id) < 3 { - id = "_" + id + name := id + for len(name) < 3 { + name = "_" + name } - return path.Join(s.Folder, subfolder, id[0:1], id[1:3], id) + return path.Join(s.Folder, subfolder, name[0:1], name[1:3], id) } func (s *Storage) readInput(w io.Writer, r io.Reader) (hash string, size int64, err error) { -- cgit