From cfe9ad992e34d52ea69f596cc32851631eab4399 Mon Sep 17 00:00:00 2001 From: Graham Steffaniak <42989099+gtsteffaniak@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:06:26 -0600 Subject: [PATCH] fix single download issue (#3420) --- backend/pkg/settings/unix_peer_stub.go | 4 --- backend/pkg/settings/unix_socket_test.go | 15 ++++++++-- frontend/src/api/resources.js | 19 ++++++++---- frontend/src/utils/download.js | 37 ++++++++++++++++++++---- 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/backend/pkg/settings/unix_peer_stub.go b/backend/pkg/settings/unix_peer_stub.go index c34e5786f..7fd72a8ae 100644 --- a/backend/pkg/settings/unix_peer_stub.go +++ b/backend/pkg/settings/unix_peer_stub.go @@ -7,10 +7,6 @@ import ( "net" ) -func peerCredentialFromConn(net.Conn) (UnixPeerCredential, bool) { - return UnixPeerCredential{}, false -} - func attachUnixPeerContext(ctx context.Context, _ net.Conn) context.Context { return ctx } diff --git a/backend/pkg/settings/unix_socket_test.go b/backend/pkg/settings/unix_socket_test.go index 23febb2d5..7b5bee64d 100644 --- a/backend/pkg/settings/unix_socket_test.go +++ b/backend/pkg/settings/unix_socket_test.go @@ -2,7 +2,6 @@ package settings import ( "os" - "path/filepath" "runtime" "testing" ) @@ -61,13 +60,23 @@ func TestListenUnixFilesystemSetsModeWithRestrictiveUmask(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("filesystem unix sockets are not used on Windows") } + // Bind uses sockaddr_un.sun_path; macOS allows at most 104 bytes, so use a short + // relative path in the test working directory (not the long t.TempDir() absolute path). dir := t.TempDir() - socketPath := filepath.Join(dir, "fb.sock") + wd, err := os.Getwd() + if err != nil { + t.Fatal(err) + } + if chdirErr := os.Chdir(dir); chdirErr != nil { + t.Fatal(chdirErr) + } + socketPath := "fb.sock" orig := Config.Http Config.Http.SocketFileMode = "" t.Cleanup(func() { - Config.Http = orig _ = os.Remove(socketPath) + _ = os.Chdir(wd) + Config.Http = orig }) ln, err := ListenUnixFilesystem(socketPath) if err != nil { diff --git a/frontend/src/api/resources.js b/frontend/src/api/resources.js index f887ef658..d289ccf60 100644 --- a/frontend/src/api/resources.js +++ b/frontend/src/api/resources.js @@ -285,12 +285,16 @@ export async function put(source, path, content = '') { return await resourceAction(source, path, 'PUT', content) } +function isDirectoryItem(item) { + return item?.isDir === true || item?.type === "directory" +} + export async function download(format, files, shareHash = "") { const downloadChunkSizeMb = state.user?.fileLoading?.downloadChunkSizeMb || 0 const sizeThreshold = downloadChunkSizeMb * 1024 * 1024 const isMultiItemArchive = - files.length > 1 || (files.length === 1 && files[0].isDir) + files.length > 1 || (files.length === 1 && isDirectoryItem(files[0])) const useChunkedArchive = downloadChunkSizeMb > 0 && isMultiItemArchive @@ -298,7 +302,7 @@ export async function download(format, files, shareHash = "") { const useChunkedDownload = downloadChunkSizeMb > 0 && files.length === 1 && - !files[0].isDir && + !isDirectoryItem(files[0]) && files[0].size && files[0].size >= sizeThreshold @@ -444,7 +448,7 @@ async function resolveDownloadContentLength(url) { function archiveDisplayFileName(format, files) { const ext = format === 'zip' ? '.zip' : '.tar.gz' const first = files[0] - if (files.length === 1 && first.isDir) { + if (files.length === 1 && isDirectoryItem(first)) { const base = first.name || (first.path?.split('/').filter(Boolean).pop()) || @@ -614,9 +618,14 @@ async function downloadChunkedArchive(url, format, files, filePaths, source, sha } const chunkSize = downloadChunkSizeMb * 1024 * 1024 const fileName = archiveDisplayFileName(format, files) - const { size: fileSize, token } = await resolveDownloadContentLength(url) + const sizeProbeMessage = 'Could not determine archive size for chunked download' + const { size: fileSize, token } = await resolveDownloadContentLength(url).catch((error) => { + notifyDownloadError(fileName, error?.message || sizeProbeMessage) + throw error + }) if (!fileSize || fileSize <= 0) { - throw new Error('Could not determine archive size for chunked download') + notifyDownloadError(fileName, sizeProbeMessage) + throw new Error(sizeProbeMessage) } const baseUrl = appendArchiveTokenToUrl(url, token) diff --git a/frontend/src/utils/download.js b/frontend/src/utils/download.js index 0fa54da56..2606fa0ce 100644 --- a/frontend/src/utils/download.js +++ b/frontend/src/utils/download.js @@ -2,6 +2,14 @@ import { resourcesApi } from "@/api/index.js"; import { notify } from "@/notify/index.ts"; import { getters, mutations, state } from "@/store/index.ts"; +function isItemDirectory(item) { + return item?.isDir === true || item?.type === "directory"; +} + +function isSingleFileItem(items) { + return items.length === 1 && !isItemDirectory(items[0]); +} + export default function downloadFiles(items) { if (items.length === 0) { notify.showError("No files selected"); @@ -19,12 +27,12 @@ export default function downloadFiles(items) { const willUseChunkedDownload = downloadChunkSizeMb > 0 && items.length === 1 && - !items[0].isDir && + !isItemDirectory(items[0]) && items[0].size && items[0].size >= sizeThreshold const isMultiItemArchive = - items.length > 1 || (items.length === 1 && items[0].isDir) + items.length > 1 || (items.length === 1 && isItemDirectory(items[0])) const willUseChunkedArchive = downloadChunkSizeMb > 0 && isMultiItemArchive @@ -34,7 +42,7 @@ export default function downloadFiles(items) { if (getters.isShare()) { // Perform download without opening a new window - if (getters.isSingleFileSelected()) { + if (isSingleFileItem(items)) { if (showChunkedProgressFirst) { mutations.showPrompt({ name: "download" }); void startDownload(null, items, state.shareInfo.hash, { @@ -58,7 +66,7 @@ export default function downloadFiles(items) { return; } - if (getters.isSingleFileSelected()) { + if (isSingleFileItem(items)) { if (showChunkedProgressFirst) { mutations.showPrompt({ name: "download" }); void startDownload(null, items, "", { silentChunkedError: true }); @@ -105,11 +113,30 @@ export function showShareDownloadPrompt(items) { } const downloadChunkSizeMb = state.user?.fileLoading?.downloadChunkSizeMb || 0; + const sizeThreshold = downloadChunkSizeMb * 1024 * 1024; + const willUseChunkedDownload = + downloadChunkSizeMb > 0 && + items.length === 1 && + !isItemDirectory(items[0]) && + items[0].size && + items[0].size >= sizeThreshold; const isMultiItemArchive = - items.length > 1 || (items.length === 1 && items[0].isDir); + items.length > 1 || (items.length === 1 && isItemDirectory(items[0])); const willUseChunkedArchive = downloadChunkSizeMb > 0 && isMultiItemArchive; + if (isSingleFileItem(items)) { + if (willUseChunkedDownload) { + mutations.showPrompt({ name: "download" }); + void startDownload(null, items, state.shareInfo?.hash || "", { + silentChunkedError: true, + }); + } else { + void startDownload(null, items, state.shareInfo?.hash || ""); + } + return; + } + mutations.showPrompt({ name: "download", confirm: (format) => {