File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -373,14 +373,15 @@ export const checkS3Object = async (
373
373
s3Client : S3Client ,
374
374
bucketName : string ,
375
375
root : string ,
376
- path ?: string
376
+ path ?: string ,
377
+ isDir ?: boolean
377
378
) : Promise < void > => {
378
379
// checking the existance of an S3 object
379
380
if ( path ) {
380
381
await s3Client . send (
381
382
new HeadObjectCommand ( {
382
383
Bucket : bucketName ,
383
- Key : PathExt . join ( root , path )
384
+ Key : PathExt . join ( root , path ) + ( isDir === true ? '/' : '' )
384
385
} )
385
386
) ;
386
387
}
@@ -657,8 +658,12 @@ export const countS3ObjectNameAppearances = async (
657
658
658
659
if ( Contents ) {
659
660
Contents . forEach ( c => {
660
- const fileName = c
661
- . Key ! . replace ( ( root ? root + '/' : '' ) + ( path ? path + '/' : '' ) , '' )
661
+ let fileName =
662
+ c . Key ! [ c . Key ! . length - 1 ] === '/'
663
+ ? c . Key ! . substring ( 0 , c . Key ! . length - 1 )
664
+ : c . Key ! ;
665
+ fileName = fileName
666
+ . replace ( ( root ? root + '/' : '' ) + ( path ? path + '/' : '' ) , '' )
662
667
. split ( '/' ) [ 0 ] ;
663
668
if (
664
669
fileName . substring ( 0 , originalName . length + 1 ) . includes ( originalName )
Original file line number Diff line number Diff line change @@ -430,7 +430,13 @@ export class Drive implements Contents.IDrive {
430
430
) ;
431
431
432
432
try {
433
- await checkS3Object ( this . _s3Client , this . _name , this . _root , newLocalPath ) ;
433
+ await checkS3Object (
434
+ this . _s3Client ,
435
+ this . _name ,
436
+ this . _root ,
437
+ newLocalPath ,
438
+ isDir
439
+ ) ;
434
440
newFileName = await this . incrementName ( newLocalPath , this . _name , isDir ) ;
435
441
} catch ( error ) {
436
442
// HEAD request failed for this file name, continue, as name doesn't already exist.
@@ -471,7 +477,10 @@ export class Drive implements Contents.IDrive {
471
477
472
478
// check if we are dealing with a directory
473
479
if ( isDir === true ) {
474
- localPath = localPath . substring ( 0 , localPath . length - 1 ) ;
480
+ localPath =
481
+ localPath [ localPath . length - 1 ] === '/'
482
+ ? localPath . substring ( 0 , localPath . length - 1 )
483
+ : localPath ;
475
484
originalName = PathExt . basename ( localPath ) ;
476
485
}
477
486
// dealing with a file
You can’t perform that action at this time.
0 commit comments