From a42a5961861f638fef3b49685fc6df2eea38fa0d Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Wed, 8 Jul 2026 09:11:10 -0700 Subject: Decouple FileStore from *os.File for object-store backends The FileStore interface returned concrete *os.File from Open/Create/ OpenFile, which no non-filesystem backend (e.g. S3/R2) can produce, and many file-library hot paths bypassed the interface entirely with direct os.* / filepath.Walk calls. Widen the interface to return io.ReadCloser / io.WriteCloser and add ReadDir, ReadLink, and Walk so directory traversal no longer escapes the abstraction. Route every file-library call site (fork writers, upload/ download handlers, GetFileNameList, CalcTotalSize/CalcItemCount, the set- file-info folder rename) through the injected FileStore, and add a WithFileStore option. OSFileStore keeps byte-identical behavior. DownloadHandler now nil-guards the optional resource-fork reader instead of relying on *os.File's nil-receiver tolerance, so a backend returning an untyped-nil reader does not panic. --- internal/mobius/handlers_files.go | 4 ++-- internal/mobius/handlers_files_test.go | 2 +- internal/mobius/handlers_transfers.go | 4 ++-- internal/mobius/handlers_transfers_test.go | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) (limited to 'internal') diff --git a/internal/mobius/handlers_files.go b/internal/mobius/handlers_files.go index 4052206..cbdf61e 100644 --- a/internal/mobius/handlers_files.go +++ b/internal/mobius/handlers_files.go @@ -144,7 +144,7 @@ func HandleSetFileInfo(cc *hotline.ClientConn, t *hotline.Transaction) (res []ho if !cc.Authorize(hotline.AccessRenameFolder) { return cc.NewErrReply(t, ErrMsgNotAllowedRenameFolders) } - err = os.Rename(fullFilePath, fullNewFilePath) + err = cc.Server.FS.Rename(fullFilePath, fullNewFilePath) if os.IsNotExist(err) { return cc.NewErrReply(t, fmt.Sprintf(ErrMsgCannotRenameFolderNotFound, string(fileName))) } @@ -382,7 +382,7 @@ func HandleGetFileNameList(cc *hotline.ClientConn, t *hotline.Transaction) (res return cc.NewErrReply(t, ErrMsgNotAllowedViewDropBoxes) } - fileNames, err := hotline.GetFileNameList(fullPath, cc.Server.Config.IgnoreFiles, cc.TextEncoder(), cc.Logger) + fileNames, err := hotline.GetFileNameList(cc.Server.FS, fullPath, cc.Server.Config.IgnoreFiles, cc.TextEncoder(), cc.Logger) if err != nil { cc.Logger.Error("error getting file name list", "err", err) return cc.NewErrReply(t, "Cannot get file list.") diff --git a/internal/mobius/handlers_files_test.go b/internal/mobius/handlers_files_test.go index a2073a9..fd022bb 100644 --- a/internal/mobius/handlers_files_test.go +++ b/internal/mobius/handlers_files_test.go @@ -748,7 +748,7 @@ func TestHandleGetFileNameList(t *testing.T) { return filepath.Join(path, "/test/config/Files/getFileNameListTestDir") }(), }, - Server: &hotline.Server{TextDecoder: charmap.Macintosh.NewDecoder(), TextEncoder: charmap.Macintosh.NewEncoder()}, + Server: &hotline.Server{FS: &hotline.OSFileStore{}, TextDecoder: charmap.Macintosh.NewDecoder(), TextEncoder: charmap.Macintosh.NewEncoder()}, }, t: hotline.NewTransaction( hotline.TranGetFileNameList, [2]byte{0, 1}, diff --git a/internal/mobius/handlers_transfers.go b/internal/mobius/handlers_transfers.go index 315135e..c5eab8c 100644 --- a/internal/mobius/handlers_transfers.go +++ b/internal/mobius/handlers_transfers.go @@ -117,12 +117,12 @@ func HandleDownloadFolder(cc *hotline.ClientConn, t *hotline.Transaction) (res [ return cc.NewErrReply(t, ErrMsgFileNotFound) } - transferSize, err := hotline.CalcTotalSize(fullFilePath) + transferSize, err := hotline.CalcTotalSize(cc.Server.FS, fullFilePath) if err != nil { cc.Logger.Error("download folder: calc total size", "err", err) return cc.NewErrReply(t, ErrMsgDownloadFolder) } - itemCount, err := hotline.CalcItemCount(fullFilePath) + itemCount, err := hotline.CalcItemCount(cc.Server.FS, fullFilePath) if err != nil { cc.Logger.Error("download folder: calc item count", "err", err) return cc.NewErrReply(t, ErrMsgDownloadFolder) diff --git a/internal/mobius/handlers_transfers_test.go b/internal/mobius/handlers_transfers_test.go index 28c2768..4e4ba0f 100644 --- a/internal/mobius/handlers_transfers_test.go +++ b/internal/mobius/handlers_transfers_test.go @@ -535,6 +535,7 @@ func TestHandleDownloadFolder_withAccess(t *testing.T) { }(), }, Server: &hotline.Server{ + FS: &hotline.OSFileStore{}, TextDecoder: charmap.Macintosh.NewDecoder(), TextEncoder: charmap.Macintosh.NewEncoder(), FileTransferMgr: hotline.NewMemFileTransferMgr(), -- cgit