~emersion/soju-dev

msgstore_fs: escape "." and ".." v1 APPLIED

Hubert Hirtz: 1
 msgstore_fs: escape "." and ".."

 1 files changed, 12 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/soju-dev/patches/25242/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] msgstore_fs: escape "." and ".." Export this patch

---

 msgstore_fs.go | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/msgstore_fs.go b/msgstore_fs.go
index 5f7025b..7458bb6 100644
--- a/msgstore_fs.go
+++ b/msgstore_fs.go
@@ -16,7 +16,15 @@ import (

const fsMessageStoreMaxTries = 100

var escapeFilename = strings.NewReplacer("/", "-", "\\", "-")
func escapeFilename(unsafe string) (safe string) {
	if unsafe == "." {
		return "-"
	} else if unsafe == ".." {
		return "--"
	} else {
		return strings.NewReplacer("/", "-", "\\", "-").Replace(unsafe)
	}
}

type date struct {
	Year, Month, Day int
@@ -69,7 +77,7 @@ var _ chatHistoryMessageStore = (*fsMessageStore)(nil)

func newFSMessageStore(root, username string) *fsMessageStore {
	return &fsMessageStore{
		root:  filepath.Join(root, escapeFilename.Replace(username)),
		root:  filepath.Join(root, escapeFilename(username)),
		files: make(map[string]*os.File),
	}
}
@@ -77,7 +85,7 @@ func newFSMessageStore(root, username string) *fsMessageStore {
func (ms *fsMessageStore) logPath(network *network, entity string, t time.Time) string {
	year, month, day := t.Date()
	filename := fmt.Sprintf("%04d-%02d-%02d.log", year, month, day)
	return filepath.Join(ms.root, escapeFilename.Replace(network.GetName()), escapeFilename.Replace(entity), filename)
	return filepath.Join(ms.root, escapeFilename(network.GetName()), escapeFilename(entity), filename)
}

// nextMsgID queries the message ID for the next message to be written to f.
@@ -439,7 +447,7 @@ func (ms *fsMessageStore) LoadLatestID(network *network, entity, id string, limi
}

func (ms *fsMessageStore) ListTargets(network *network, start, end time.Time, limit int) ([]chatHistoryTarget, error) {
	rootPath := filepath.Join(ms.root, escapeFilename.Replace(network.GetName()))
	rootPath := filepath.Join(ms.root, escapeFilename(network.GetName()))
	root, err := os.Open(rootPath)
	if err != nil {
		return nil, err
-- 
2.33.0
Good catch! Thanks, pushed.