@@ -124,10 +124,12 @@ export class MockHandlers {
124
124
125
125
const prefix = key . slice ( 0 , - name . length ) ;
126
126
127
- if ( hasWebkitRelativePath && ! this . #locationItems [ prefix ] ) {
128
- // register folder prefix
127
+ // register folder prefix if missing
128
+ if ( ! this . #locationItems [ prefix ] ) {
129
129
this . #locationItems[ prefix ] = [ ] ;
130
+ }
130
131
132
+ if ( hasWebkitRelativePath ) {
131
133
// create new folder within parent prefix
132
134
const parentPrefix = key . slice ( 0 , - webkitRelativePath . length ) ;
133
135
this . #locationItems[ parentPrefix ] . push ( {
@@ -137,17 +139,21 @@ export class MockHandlers {
137
139
} ) ;
138
140
}
139
141
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
+ }
151
157
}
152
158
153
159
this . #locationItems[ prefix ] . push ( {
0 commit comments