fix: unblock stalled and frozen uploads
A TUS PATCH rejected before its body was read left the client still streaming a chunk. net/http gives up draining an unread request body after 256KiB and then closes the connection, so the status we replied with was lost and the browser saw a bare transport error instead. The client could not tell a conflict from a network fault, retried blindly, and the upload stalled after the first chunk — while curl, which reads the response as it writes, still reported the status and appeared to work. Drain what is left of a rejected chunk so the answer arrives on a connection that stays usable. The explicit r.Body.Close() had to go with it: it ran before the drain, and the server closes the request body itself once the handler returns. Pressing Upload awaited a recursive listing of the whole destination subtree before a single byte was sent, with no sign that anything was happening. On a large destination that reads as a dead button, and the walk kept running after the client gave up, then reported the failed write as a 500. A flat upload can only collide with a direct child of the destination, so walk recursively only for folder uploads, stop the walk once the request is done, and show the action as busy while the destination is checked. Along the way: a failed upload was credited as fully sent, so the progress bar reported 100% when nothing had been written; the progress timer was recreated without clearing the previous one; and the chunk size field threw on a value with no unit and raced its own debounce on submit, so it appeared to refuse every change. Fixes #6006 Refs #5987
This commit is contained in:
12 files changed
+715
-156
No files matched your search
@@ -20,6 +20,24 @@ vi.mock("@/stores/layout", () => ({ useLayoutStore: vi.fn() }));
|
||||
vi.mock("@/stores/upload", () => ({ useUploadStore: vi.fn() }));
|
||||
vi.mock("@/utils/url", () => ({ default: {} }));
|
||||
|
||||
type ServerEntry = {
|
||||
path: string;
|
||||
name: string;
|
||||
size: number;
|
||||
modified: string;
|
||||
isDir: boolean;
|
||||
};
|
||||
|
||||
// The destination's direct listing, used for copy/move and for flat uploads.
|
||||
function mockListing(entries: ServerEntry[]) {
|
||||
vi.mocked(api.fetch).mockResolvedValue({ items: entries } as Resource);
|
||||
}
|
||||
|
||||
// The recursive walk of the destination, used only for nested (folder) uploads.
|
||||
function mockRecursiveListing(entries: ServerEntry[]) {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue(entries);
|
||||
}
|
||||
|
||||
// A move/copy/drag item carries name (raw) and to (URL-encoded) but no
|
||||
// fullPath - mirroring what Move.vue / Copy.vue / ListingItem.vue build.
|
||||
function moveItem(name: string, dest: string, size = 12) {
|
||||
@@ -40,7 +58,7 @@ describe("checkConflict", () => {
|
||||
});
|
||||
|
||||
it("detects a conflict for a plain filename", async () => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockListing([
|
||||
{
|
||||
path: "/target/file.txt",
|
||||
name: "file.txt",
|
||||
@@ -59,6 +77,43 @@ describe("checkConflict", () => {
|
||||
expect(conflicts[0].name).toBe("/target/file.txt");
|
||||
});
|
||||
|
||||
// Regression for #6006: pressing Upload awaited a full server-side recursive
|
||||
// walk of the destination before a single byte was sent, so the UI sat there
|
||||
// doing nothing on a large destination. A flat upload can only collide with a
|
||||
// direct child, which the plain listing already covers.
|
||||
it("does not walk the destination tree for a flat upload", async () => {
|
||||
mockListing([]);
|
||||
|
||||
await checkConflict(
|
||||
[{ name: "file.txt", size: 12, isDir: false }],
|
||||
"/files/target/"
|
||||
);
|
||||
|
||||
expect(api.fetch).toHaveBeenCalledWith("/files/target/");
|
||||
expect(api.fetchAll).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// ...but a folder upload lands entries below the destination, so it still
|
||||
// needs the recursive listing to see them.
|
||||
it("walks the destination tree for a nested upload", async () => {
|
||||
mockRecursiveListing([]);
|
||||
|
||||
await checkConflict(
|
||||
[
|
||||
{
|
||||
name: "file.txt",
|
||||
size: 12,
|
||||
isDir: false,
|
||||
fullPath: "folder/file.txt",
|
||||
},
|
||||
],
|
||||
"/files/target/"
|
||||
);
|
||||
|
||||
expect(api.fetchAll).toHaveBeenCalledWith("/files/target/");
|
||||
expect(api.fetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Regression for #5957: names with encodable characters (spaces, "#",
|
||||
// non-ASCII) were keyed by the URL-encoded `to` value and never matched the
|
||||
// server's raw path, so the conflict modal was skipped and the backend
|
||||
@@ -66,7 +121,7 @@ describe("checkConflict", () => {
|
||||
it.each(["my file.txt", "résumé.pdf", "a#b.txt"])(
|
||||
"detects a conflict for %s (encodable characters)",
|
||||
async (name) => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockListing([
|
||||
{
|
||||
path: `/target/${name}`,
|
||||
name,
|
||||
@@ -87,7 +142,7 @@ describe("checkConflict", () => {
|
||||
);
|
||||
|
||||
it("reports no conflict when the destination has no matching name", async () => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockListing([
|
||||
{
|
||||
path: "/target/other.txt",
|
||||
name: "other.txt",
|
||||
@@ -106,7 +161,7 @@ describe("checkConflict", () => {
|
||||
});
|
||||
|
||||
it("detects nested conflicts for folder uploads via fullPath", async () => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockRecursiveListing([
|
||||
{
|
||||
path: "/target/folder",
|
||||
name: "folder",
|
||||
@@ -143,7 +198,7 @@ describe("checkConflict", () => {
|
||||
// fullPath) and no directory entries. Conflict detection must still find a
|
||||
// nested file even though its parent folder is not in the upload list.
|
||||
it("detects nested conflicts when no directory entries are present", async () => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockRecursiveListing([
|
||||
{
|
||||
path: "/target/folder/deep/file.txt",
|
||||
name: "file.txt",
|
||||
@@ -171,24 +226,22 @@ describe("checkConflict", () => {
|
||||
// Copy/move only needs the target directory's direct children. A recursive
|
||||
// walk can make the UI look frozen on large destinations (regression #6005).
|
||||
it("checks only the direct destination listing for copy/move", async () => {
|
||||
vi.mocked(api.fetch).mockResolvedValue({
|
||||
items: [
|
||||
{
|
||||
path: "/target/file.txt",
|
||||
name: "file.txt",
|
||||
size: 10,
|
||||
modified: "2026-06-04T00:00:00Z",
|
||||
isDir: false,
|
||||
},
|
||||
{
|
||||
path: "/target/folder",
|
||||
name: "folder",
|
||||
size: 0,
|
||||
modified: "2026-06-04T00:00:00Z",
|
||||
isDir: true,
|
||||
},
|
||||
],
|
||||
} as Resource);
|
||||
mockListing([
|
||||
{
|
||||
path: "/target/file.txt",
|
||||
name: "file.txt",
|
||||
size: 10,
|
||||
modified: "2026-06-04T00:00:00Z",
|
||||
isDir: false,
|
||||
},
|
||||
{
|
||||
path: "/target/folder",
|
||||
name: "folder",
|
||||
size: 0,
|
||||
modified: "2026-06-04T00:00:00Z",
|
||||
isDir: true,
|
||||
},
|
||||
]);
|
||||
|
||||
const items = [
|
||||
moveItem("file.txt", "/files/target/"),
|
||||
@@ -209,7 +262,7 @@ describe("checkConflict", () => {
|
||||
// Uploads merge into an existing folder, so the directory itself must not be
|
||||
// reported - only the files inside it can conflict.
|
||||
it("ignores a directory conflict for uploads (default)", async () => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockListing([
|
||||
{
|
||||
path: "/target/folder",
|
||||
name: "folder",
|
||||
@@ -228,8 +281,8 @@ describe("checkConflict", () => {
|
||||
expect(conflicts).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("returns no conflicts when the recursive listing fails", async () => {
|
||||
vi.mocked(api.fetchAll).mockRejectedValue(new Error("404"));
|
||||
it("returns no conflicts when the destination listing fails", async () => {
|
||||
vi.mocked(api.fetch).mockRejectedValue(new Error("404"));
|
||||
|
||||
const conflicts = await checkConflict(
|
||||
[moveItem("file.txt", "/files/target/")],
|
||||
@@ -240,11 +293,11 @@ describe("checkConflict", () => {
|
||||
});
|
||||
|
||||
// Regression for #5980: a FileBrowser server running on Windows returns
|
||||
// backslash-separated paths from the recursive listing. Without normalizing
|
||||
// them, the prefix strip and key lookup never match, so the conflict modal is
|
||||
// skipped and the backend returns a bare 409.
|
||||
// backslash-separated paths, Without normalizing them, the prefix strip and
|
||||
// key lookup never match, so the conflict modal is skipped and the backend
|
||||
// returns a bare 409.
|
||||
it("detects a conflict for backslash-separated server paths (Windows)", async () => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockListing([
|
||||
{
|
||||
path: "\\target\\file.txt",
|
||||
name: "file.txt",
|
||||
@@ -263,7 +316,7 @@ describe("checkConflict", () => {
|
||||
});
|
||||
|
||||
it("detects nested conflicts for backslash-separated server paths (Windows)", async () => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockRecursiveListing([
|
||||
{
|
||||
path: "\\target\\folder\\nested file.txt",
|
||||
name: "nested file.txt",
|
||||
@@ -293,7 +346,7 @@ describe("checkConflict", () => {
|
||||
])(
|
||||
"detects conflicts below an encoded destination path with %s",
|
||||
async (_label, serverPath) => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockListing([
|
||||
{
|
||||
path: serverPath,
|
||||
name: "file.txt",
|
||||
@@ -314,7 +367,7 @@ describe("checkConflict", () => {
|
||||
);
|
||||
|
||||
it("detects nested folder-upload conflicts below an encoded destination path", async () => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockRecursiveListing([
|
||||
{
|
||||
path: "\\target\\My SubDir\\folder\\nested file.txt",
|
||||
name: "nested file.txt",
|
||||
@@ -341,7 +394,7 @@ describe("checkConflict", () => {
|
||||
});
|
||||
|
||||
it("leaves malformed destination path segments unchanged", async () => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockListing([
|
||||
{
|
||||
path: "/target/bad%ZZ/file.txt",
|
||||
name: "file.txt",
|
||||
@@ -360,7 +413,7 @@ describe("checkConflict", () => {
|
||||
});
|
||||
|
||||
it("does not match files outside the decoded destination path", async () => {
|
||||
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||
mockRecursiveListing([
|
||||
{
|
||||
path: "/target/My SubDir/other.txt",
|
||||
name: "other.txt",
|
||||
@@ -369,7 +422,7 @@ describe("checkConflict", () => {
|
||||
isDir: false,
|
||||
},
|
||||
{
|
||||
path: "/target/My Other SubDir/file.txt",
|
||||
path: "/target/My Other SubDir/folder/file.txt",
|
||||
name: "file.txt",
|
||||
size: 10,
|
||||
modified: "2026-06-04T00:00:00Z",
|
||||
@@ -378,7 +431,14 @@ describe("checkConflict", () => {
|
||||
]);
|
||||
|
||||
const conflicts = await checkConflict(
|
||||
[moveItem("file.txt", "/files/target/My%20SubDir/")],
|
||||
[
|
||||
{
|
||||
name: "file.txt",
|
||||
size: 12,
|
||||
isDir: false,
|
||||
fullPath: "folder/file.txt",
|
||||
},
|
||||
],
|
||||
"/files/target/My%20SubDir/"
|
||||
);
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ type ServerConflictEntry = {
|
||||
|
||||
async function fetchConflictEntries(
|
||||
basePath: string,
|
||||
includeDirectories: boolean
|
||||
recursive: boolean
|
||||
): Promise<ServerConflictEntry[]> {
|
||||
if (!includeDirectories) {
|
||||
if (recursive) {
|
||||
return await api.fetchAll(basePath);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,14 @@ async function fetchConflictEntries(
|
||||
return destination.items ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether any entry lands below the destination rather than directly in it.
|
||||
* Only then does conflict detection need the whole destination tree.
|
||||
*/
|
||||
function hasNestedEntries(files: UploadList): boolean {
|
||||
return files.some((file) => conflictKey(file).includes("/"));
|
||||
}
|
||||
|
||||
function conflictPath(entry: ServerConflictEntry): string {
|
||||
return entry.path.replace(/\\/g, "/");
|
||||
}
|
||||
@@ -84,11 +92,14 @@ function buildConflictMap(
|
||||
* server, so the caller can prompt the user to overwrite/rename/skip.
|
||||
*
|
||||
* Directory handling differs by action, hence `includeDirectories`:
|
||||
* - Upload (false): the destination tree is fetched recursively so nested
|
||||
* file uploads can be checked; existing folders are silently merged.
|
||||
* - Copy/move (true): only the destination directory itself is fetched. These
|
||||
* operations move flat top-level selections, so a same-named direct child is
|
||||
* the only preflight conflict the backend will reject.
|
||||
* - Upload (false): existing folders are silently merged, so only files count.
|
||||
* - Copy/move (true): these move flat top-level selections, so a same-named
|
||||
* direct child is the only preflight conflict the backend will reject.
|
||||
*
|
||||
* The destination tree is only walked recursively when an entry actually lands
|
||||
* below the destination (a folder upload). Walking it for a flat upload made
|
||||
* pressing Upload wait on a full server-side walk of the whole subtree before
|
||||
* a single byte was sent, which reads as a frozen UI on a large destination.
|
||||
*
|
||||
* @param files - flat upload list to check
|
||||
* @param basePath - server destination path (e.g. "/files/uploads/")
|
||||
@@ -101,9 +112,11 @@ export async function checkConflict(
|
||||
): Promise<ConflictingResource[]> {
|
||||
if (files.length === 0) return [];
|
||||
|
||||
const recursive = !includeDirectories && hasNestedEntries(files);
|
||||
|
||||
let serverEntries: ServerConflictEntry[];
|
||||
try {
|
||||
serverEntries = await fetchConflictEntries(basePath, includeDirectories);
|
||||
serverEntries = await fetchConflictEntries(basePath, recursive);
|
||||
} catch {
|
||||
// The destination doesn't exist yet, so nothing can conflict.
|
||||
return [];
|
||||
|
||||
Reference in new issue
Block a user