@@ -206,6 +206,78 @@ describe('LegacyFSController.mkdir', () => {
206206 expect ( fetched ?. isDir ) . toBe ( true ) ;
207207 } ) ;
208208
209+ it ( 'dedupes an existing directory when dedupe_name is true' , async ( ) => {
210+ const { actor } = await makeUser ( ) ;
211+ const username = actor . user ! . username ! ;
212+ const parent = `/${ username } /Documents` ;
213+
214+ await withActor ( actor , ( ) =>
215+ controller . mkdir (
216+ makeReq ( {
217+ body : { parent, path : 'hello' } ,
218+ actor,
219+ } ) ,
220+ makeRes ( ) . res ,
221+ ) ,
222+ ) ;
223+
224+ const { res, captured } = makeRes ( ) ;
225+ await withActor ( actor , ( ) =>
226+ controller . mkdir (
227+ makeReq ( {
228+ body : { parent, path : 'hello' , dedupe_name : true } ,
229+ actor,
230+ } ) ,
231+ res ,
232+ ) ,
233+ ) ;
234+
235+ const body = captured . body as Record < string , unknown > ;
236+ expect ( body ) . toMatchObject ( {
237+ path : `${ parent } /hello (1)` ,
238+ name : 'hello (1)' ,
239+ is_dir : true ,
240+ } ) ;
241+ expect (
242+ await server . stores . fsEntry . getEntryByPath ( `${ parent } /hello (1)` ) ,
243+ ) . toMatchObject ( { isDir : true } ) ;
244+ } ) ;
245+
246+ it ( 'requires parent write when deduping an existing directory' , async ( ) => {
247+ const { actor : userActor } = await makeUser ( ) ;
248+ const username = userActor . user ! . username ! ;
249+ const appUid = `app-legacy-mkdir-${ uuidv4 ( ) } ` ;
250+ const appActor : Actor = { ...userActor , app : { uid : appUid } } ;
251+ const parent = `/${ username } /AppData` ;
252+
253+ await withActor ( userActor , ( ) =>
254+ controller . mkdir (
255+ makeReq ( {
256+ body : { parent, path : appUid } ,
257+ actor : userActor ,
258+ } ) ,
259+ makeRes ( ) . res ,
260+ ) ,
261+ ) ;
262+
263+ await expect (
264+ withActor ( appActor , ( ) =>
265+ controller . mkdir (
266+ makeReq ( {
267+ body : { parent, path : appUid , dedupe_name : true } ,
268+ actor : appActor ,
269+ } ) ,
270+ makeRes ( ) . res ,
271+ ) ,
272+ ) ,
273+ ) . rejects . toMatchObject ( { statusCode : 404 } ) ;
274+ expect (
275+ await server . stores . fsEntry . getEntryByPath (
276+ `${ parent } /${ appUid } (1)` ,
277+ ) ,
278+ ) . toBeNull ( ) ;
279+ } ) ;
280+
209281 it ( "rejects writing into another user's home with a 4xx" , async ( ) => {
210282 const a = await makeUser ( ) ;
211283 const b = await makeUser ( ) ;
0 commit comments