@@ -432,7 +432,23 @@ class LDP {
432
432
}
433
433
}
434
434
435
- getAvailablePath ( host , containerURI , { slug = uuid . v1 ( ) , extension } ) {
435
+ async getAvailablePath ( host , containerURI , { slug = uuid . v1 ( ) , extension } ) {
436
+ const fileName = slug + extension
437
+ function ensureNotExists ( self , newPath ) {
438
+ // Verify whether the new path already exists
439
+ return self . exists ( host , newPath ) . then (
440
+ // If it does, generate another one
441
+ ( ) => ensureNotExists ( self , URI . joinPaths ( containerURI ,
442
+ `${ uuid . v1 ( ) . split ( '-' ) [ 0 ] } -${ fileName } ` ) . toString ( ) ) ,
443
+ // If not, we found an appropriate path
444
+ ( ) => newPath
445
+ )
446
+ }
447
+ const relativePath = await ensureNotExists ( this , URI . joinPaths ( containerURI , fileName ) . toString ( ) )
448
+ return this . resourceMapper . resolveRelativeFilePath ( host , relativePath )
449
+ }
450
+
451
+ oldGetAvailablePath ( host , containerURI , { slug = uuid . v1 ( ) , extension } ) {
436
452
const path = slug + extension
437
453
function ensureNotExists ( self , newPath ) {
438
454
// Verify whether the new path already exists
0 commit comments