@@ -124,10 +124,12 @@ export class MockHandlers {
124124
125125 const prefix = key . slice ( 0 , - name . length ) ;
126126
127- if ( hasWebkitRelativePath && ! this . #locationItems [ prefix ] ) {
128- // register folder prefix
127+ // register folder prefix if missing
128+ if ( ! this . #locationItems [ prefix ] ) {
129129 this . #locationItems[ prefix ] = [ ] ;
130+ }
130131
132+ if ( hasWebkitRelativePath ) {
131133 // create new folder within parent prefix
132134 const parentPrefix = key . slice ( 0 , - webkitRelativePath . length ) ;
133135 this . #locationItems[ parentPrefix ] . push ( {
@@ -137,17 +139,21 @@ export class MockHandlers {
137139 } ) ;
138140 }
139141
140- if (
141- preventOverwrite &&
142- this . #locationItems[ prefix ] . some ( ( item ) => item . key === key )
143- ) {
144- return {
145- ...UNDEFINED_CALLBACKS ,
146- result : Promise . resolve ( {
147- error : new Error ( 'cannot overwrite existing file' ) ,
148- status : 'OVERWRITE_PREVENTED' ,
149- } ) ,
150- } ;
142+ if ( this . #locationItems[ prefix ] . some ( ( item ) => item . key === key ) ) {
143+ if ( preventOverwrite ) {
144+ return {
145+ ...UNDEFINED_CALLBACKS ,
146+ result : Promise . resolve ( {
147+ error : new Error ( 'cannot overwrite existing file' ) ,
148+ status : 'OVERWRITE_PREVENTED' ,
149+ } ) ,
150+ } ;
151+ } else {
152+ // remove prev item as new version will be added, 'overwriting' prev item
153+ this . #locationItems[ prefix ] = this . #locationItems[ prefix ] . filter (
154+ ( item ) => item . key !== key
155+ ) ;
156+ }
151157 }
152158
153159 this . #locationItems[ prefix ] . push ( {
0 commit comments