File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ export class DiskStorage extends BaseStorage<DiskFile> {
105105 async delete ( { id } : FilePart ) : Promise < DiskFile [ ] > {
106106 try {
107107 const file = await this . getMeta ( id ) ;
108- await removeFile ( this . getFilePath ( file ) ) ;
108+ removeFile ( this . getFilePath ( file ) ) . catch ( ( ) => null ) ;
109109 await this . deleteMeta ( id ) ;
110110 return [ { ...file , status : 'deleted' } ] ;
111111 } catch { }
Original file line number Diff line number Diff line change @@ -28,8 +28,10 @@ export async function accessCheck(dir: string): Promise<void> {
2828 * Removes the specified file from the local file system
2929 */
3030export async function removeFile ( path : string ) : Promise < void > {
31- if ( fsp . rm ) return fsp . rm ( path ) ;
32- return fsp . unlink ( path ) ;
31+ if ( fsp . rm ) return fsp . rm ( path , { force : true } ) ;
32+ return fsp . unlink ( path ) . catch ( ( err : NodeJS . ErrnoException ) : void => {
33+ if ( err . code !== 'ENOENT' ) throw err ;
34+ } ) ;
3335}
3436
3537export function truncateFile ( path : string , length = 0 ) : Promise < void > {
Original file line number Diff line number Diff line change @@ -81,6 +81,17 @@ describe('utils', () => {
8181 it ( 'getWriteStream(not exist , 0)' , ( ) => {
8282 expect ( ( ) => utils . getWriteStream ( '' , 0 ) ) . toThrow ( ) ;
8383 } ) ;
84+
85+ it ( 'removeFile(path)' , async ( ) => {
86+ await utils . ensureFile ( filepath ) ;
87+ await utils . removeFile ( filepath ) ;
88+ expect ( fs . existsSync ( filepath ) ) . toBe ( false ) ;
89+ } ) ;
90+
91+ it ( 'removeFile(not exist)' , async ( ) => {
92+ await utils . removeFile ( filepath ) ;
93+ expect ( fs . existsSync ( filepath ) ) . toBe ( false ) ;
94+ } ) ;
8495 } ) ;
8596
8697 describe ( 'http' , ( ) => {
You can’t perform that action at this time.
0 commit comments