Skip to content

Commit 4137f61

Browse files
authored
Merge pull request #2002 from nextcloud-libraries/fix/queue-not-empty-on-all-skip
fix(uploader): queue is not empty when everything is skipped
2 parents 093cc82 + fe2bced commit 4137f61

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

__tests__/uploader.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,19 @@ describe('Uploader', () => {
122122
expect(() => { uploader.destination = newDestination as unknown as nextcloudFiles.Folder }).toThrowError(/invalid destination/i)
123123
})
124124
})
125+
126+
describe('batchUpload', () => {
127+
test('No upload when skipping all in conflict picker', async () => {
128+
const uploader = new Uploader()
129+
await uploader.batchUpload('/', [new File([], 'file.txt')], () => Promise.resolve([]))
130+
vi.spyOn(uploader, 'upload')
131+
expect(uploader.upload).not.toHaveBeenCalled()
132+
})
133+
134+
test('Empty queue when skipping all in conflict picker', async () => {
135+
const uploader = new Uploader()
136+
await uploader.batchUpload('/', [new File([], 'file.txt')], () => Promise.resolve([]))
137+
expect(uploader.queue).toHaveLength(0)
138+
})
139+
})
125140
})

lib/uploader/uploader.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ export class Uploader {
326326
reject(error)
327327
}
328328
} finally {
329+
// Upload queue is cleared when all the uploading jobs are done
330+
// Meta upload unlike real uploading does not create a job
331+
// Removing it manually here to make sure it is remove even when no uploading happened and there was nothing to finish
332+
this._uploadQueue.splice(this._uploadQueue.indexOf(upload), 1)
329333
this._notifyAll(upload)
330334
this.updateStats()
331335
}

0 commit comments

Comments
 (0)