@@ -191,7 +191,11 @@ export class ArDrive extends ArDriveAnonymous {
191
191
}
192
192
193
193
// Assert that there are no duplicate names in the destination folder
194
- const entityNamesInParentFolder = await this . arFsDao . getPublicEntityNamesInFolder ( newParentFolderId , owner ) ;
194
+ const entityNamesInParentFolder = await this . arFsDao . getPublicEntityNamesInFolder (
195
+ newParentFolderId ,
196
+ owner ,
197
+ destFolderDriveId
198
+ ) ;
195
199
if ( entityNamesInParentFolder . includes ( originalFileMetaData . name ) ) {
196
200
// TODO: Add optional interactive prompt to resolve name conflicts in ticket PE-599
197
201
throw new Error ( errorMessage . entityNameExists ) ;
@@ -269,7 +273,8 @@ export class ArDrive extends ArDriveAnonymous {
269
273
const entityNamesInParentFolder = await this . arFsDao . getPrivateEntityNamesInFolder (
270
274
newParentFolderId ,
271
275
owner ,
272
- driveKey
276
+ driveKey ,
277
+ destFolderDriveId
273
278
) ;
274
279
if ( entityNamesInParentFolder . includes ( originalFileMetaData . name ) ) {
275
280
// TODO: Add optional interactive prompt to resolve name conflicts in ticket PE-599
@@ -353,7 +358,11 @@ export class ArDrive extends ArDriveAnonymous {
353
358
}
354
359
355
360
// Assert that there are no duplicate names in the destination folder
356
- const entityNamesInParentFolder = await this . arFsDao . getPublicEntityNamesInFolder ( newParentFolderId , owner ) ;
361
+ const entityNamesInParentFolder = await this . arFsDao . getPublicEntityNamesInFolder (
362
+ newParentFolderId ,
363
+ owner ,
364
+ destFolderDriveId
365
+ ) ;
357
366
if ( entityNamesInParentFolder . includes ( originalFolderMetaData . name ) ) {
358
367
// TODO: Add optional interactive prompt to resolve name conflicts in ticket PE-599
359
368
throw new Error ( errorMessage . entityNameExists ) ;
@@ -439,7 +448,8 @@ export class ArDrive extends ArDriveAnonymous {
439
448
const entityNamesInParentFolder = await this . arFsDao . getPrivateEntityNamesInFolder (
440
449
newParentFolderId ,
441
450
owner ,
442
- driveKey
451
+ driveKey ,
452
+ destFolderDriveId
443
453
) ;
444
454
if ( entityNamesInParentFolder . includes ( originalFolderMetaData . name ) ) {
445
455
// TODO: Add optional interactive prompt to resolve name conflicts in ticket PE-599
@@ -523,14 +533,14 @@ export class ArDrive extends ArDriveAnonymous {
523
533
const resolvedEntitiesToUpload : UploadStats [ ] = [ ] ;
524
534
525
535
for ( const entity of entitiesToUpload ) {
526
- const { destFolderId, wrappedEntity, driveKey, owner, destName } = entity ;
536
+ const { destFolderId, wrappedEntity, driveKey, owner, destName, destDriveId } = entity ;
527
537
528
538
const resolveConflictParams = {
529
539
conflictResolution,
530
540
getConflictInfoFn : ( folderId : FolderID ) =>
531
541
driveKey
532
- ? this . arFsDao . getPrivateNameConflictInfoInFolder ( folderId , owner , driveKey )
533
- : this . arFsDao . getPublicNameConflictInfoInFolder ( folderId , owner ) ,
542
+ ? this . arFsDao . getPrivateNameConflictInfoInFolder ( folderId , owner , driveKey , destDriveId )
543
+ : this . arFsDao . getPublicNameConflictInfoInFolder ( folderId , owner , destDriveId ) ,
534
544
prompts,
535
545
destFolderId
536
546
} ;
@@ -729,6 +739,7 @@ export class ArDrive extends ArDriveAnonymous {
729
739
destinationFolderId
730
740
} : RetryPublicArFSFileByDestFolderIdParams ) : Promise < ArFSResult > {
731
741
const metaDataTx = await this . deriveMetaDataTxFromPublicFolder ( destinationFolderId , dataTxId ) ;
742
+ const driveId = await this . arFsDao . getDriveIdForFolderId ( destinationFolderId ) ;
732
743
733
744
let metaDataTxId : undefined | TransactionID = undefined ;
734
745
let createMetaDataPlan : undefined | ArFSCreateFileMetaDataV2Plan = undefined ;
@@ -743,7 +754,8 @@ export class ArDrive extends ArDriveAnonymous {
743
754
const isValidUpload = await this . assertWriteFileMetaData ( {
744
755
wrappedFile,
745
756
conflictResolution,
746
- destinationFolderId
757
+ destinationFolderId,
758
+ driveId
747
759
} ) ;
748
760
749
761
if ( ! isValidUpload ) {
@@ -827,11 +839,13 @@ export class ArDrive extends ArDriveAnonymous {
827
839
dataTxId : TransactionID
828
840
) : Promise < ArFSPublicFile | undefined > {
829
841
const owner = await this . wallet . getAddress ( ) ;
842
+ const driveId = await this . arFsDao . getDriveIdForFolderId ( destinationFolderId ) ;
830
843
await this . assertFolderExists ( destinationFolderId , owner ) ;
831
844
832
845
const allFileMetaDataTxInFolder = await this . arFsDao . getPublicFilesWithParentFolderIds (
833
846
[ destinationFolderId ] ,
834
- owner
847
+ owner ,
848
+ driveId
835
849
) ;
836
850
const metaDataTxsForThisTx = allFileMetaDataTxInFolder . filter ( ( f ) => `${ f . dataTxId } ` === `${ dataTxId } ` ) ;
837
851
@@ -853,19 +867,22 @@ export class ArDrive extends ArDriveAnonymous {
853
867
private async assertWriteFileMetaData ( {
854
868
wrappedFile,
855
869
destinationFolderId,
856
- conflictResolution
870
+ conflictResolution,
871
+ driveId
857
872
} : {
858
873
wrappedFile : ArFSFileToUpload ;
859
874
destinationFolderId : FolderID ;
860
875
conflictResolution : FileNameConflictResolution ;
876
+ driveId : DriveID ;
861
877
} ) : Promise < boolean > {
862
878
const owner = await this . wallet . getAddress ( ) ;
863
879
await resolveFileNameConflicts ( {
864
880
wrappedFile,
865
881
conflictResolution,
866
882
destFolderId : destinationFolderId ,
867
883
destinationFileName : wrappedFile . destinationBaseName ,
868
- getConflictInfoFn : ( folderId : FolderID ) => this . arFsDao . getPublicNameConflictInfoInFolder ( folderId , owner )
884
+ getConflictInfoFn : ( folderId : FolderID ) =>
885
+ this . arFsDao . getPublicNameConflictInfoInFolder ( folderId , owner , driveId )
869
886
} ) ;
870
887
871
888
if ( wrappedFile . conflictResolution ) {
@@ -1019,7 +1036,11 @@ export class ArDrive extends ArDriveAnonymous {
1019
1036
const owner = await this . wallet . getAddress ( ) ;
1020
1037
1021
1038
// Assert that there are no duplicate names in the destination folder
1022
- const entityNamesInParentFolder = await this . arFsDao . getPublicEntityNamesInFolder ( parentFolderId , owner ) ;
1039
+ const entityNamesInParentFolder = await this . arFsDao . getPublicEntityNamesInFolder (
1040
+ parentFolderId ,
1041
+ owner ,
1042
+ driveId
1043
+ ) ;
1023
1044
if ( entityNamesInParentFolder . includes ( folderName ) ) {
1024
1045
// TODO: Add optional interactive prompt to resolve name conflicts in ticket PE-599
1025
1046
throw new Error ( errorMessage . entityNameExists ) ;
@@ -1083,7 +1104,8 @@ export class ArDrive extends ArDriveAnonymous {
1083
1104
const entityNamesInParentFolder = await this . arFsDao . getPrivateEntityNamesInFolder (
1084
1105
parentFolderId ,
1085
1106
owner ,
1086
- driveKey
1107
+ driveKey ,
1108
+ driveId
1087
1109
) ;
1088
1110
if ( entityNamesInParentFolder . includes ( folderName ) ) {
1089
1111
// TODO: Add optional interactive prompt to resolve name conflicts in ticket PE-599
@@ -1438,10 +1460,11 @@ export class ArDrive extends ArDriveAnonymous {
1438
1460
await fileToDownload . write ( ) ;
1439
1461
}
1440
1462
1441
- async assertUniqueNameWithinPublicFolder ( name : string , folderId : FolderID ) : Promise < void > {
1463
+ async assertUniqueNameWithinPublicFolder ( name : string , folderId : FolderID , driveId : DriveID ) : Promise < void > {
1442
1464
const allSiblingNames = await this . arFsDao . getPublicEntityNamesInFolder (
1443
1465
folderId ,
1444
- await this . wallet . getAddress ( )
1466
+ await this . wallet . getAddress ( ) ,
1467
+ driveId
1445
1468
) ;
1446
1469
const collidesWithExistingSiblingName = allSiblingNames . reduce ( ( accumulator , siblingName ) => {
1447
1470
return accumulator || siblingName === name ;
@@ -1451,11 +1474,17 @@ export class ArDrive extends ArDriveAnonymous {
1451
1474
}
1452
1475
}
1453
1476
1454
- async assertUniqueNameWithinPrivateFolder ( name : string , folderId : FolderID , driveKey : DriveKey ) : Promise < void > {
1477
+ async assertUniqueNameWithinPrivateFolder (
1478
+ name : string ,
1479
+ folderId : FolderID ,
1480
+ driveKey : DriveKey ,
1481
+ driveId : DriveID
1482
+ ) : Promise < void > {
1455
1483
const allSiblingNames = await this . arFsDao . getPrivateEntityNamesInFolder (
1456
1484
folderId ,
1457
1485
await this . wallet . getAddress ( ) ,
1458
- driveKey
1486
+ driveKey ,
1487
+ driveId
1459
1488
) ;
1460
1489
const collidesWithExistingSiblingName = allSiblingNames . reduce ( ( accumulator , siblingName ) => {
1461
1490
return accumulator || siblingName === name ;
@@ -1467,13 +1496,14 @@ export class ArDrive extends ArDriveAnonymous {
1467
1496
1468
1497
async renamePublicFile ( { fileId, newName } : RenamePublicFileParams ) : Promise < ArFSResult > {
1469
1498
const owner = await this . wallet . getAddress ( ) ;
1499
+ const driveId = await this . getDriveIdForFileId ( fileId ) ;
1470
1500
1471
1501
const file = await this . getPublicFile ( { fileId, owner } ) ;
1472
1502
if ( file . name === newName ) {
1473
1503
throw new Error ( `To rename a file, the new name must be different` ) ;
1474
1504
}
1475
1505
assertValidArFSFileName ( newName ) ;
1476
- await this . assertUniqueNameWithinPublicFolder ( newName , file . parentFolderId ) ;
1506
+ await this . assertUniqueNameWithinPublicFolder ( newName , file . parentFolderId , driveId ) ;
1477
1507
const fileMetadataTxDataStub = new ArFSPublicFileMetadataTransactionData (
1478
1508
newName ,
1479
1509
file . size ,
@@ -1527,11 +1557,12 @@ export class ArDrive extends ArDriveAnonymous {
1527
1557
async renamePrivateFile ( { fileId, newName, driveKey } : RenamePrivateFileParams ) : Promise < ArFSResult > {
1528
1558
const owner = await this . wallet . getAddress ( ) ;
1529
1559
const file = await this . getPrivateFile ( { fileId, driveKey, owner } ) ;
1560
+ const driveId = await this . getDriveIdForFileId ( fileId ) ;
1530
1561
if ( file . name === newName ) {
1531
1562
throw new Error ( `To rename a file, the new name must be different` ) ;
1532
1563
}
1533
1564
assertValidArFSFileName ( newName ) ;
1534
- await this . assertUniqueNameWithinPrivateFolder ( newName , file . parentFolderId , driveKey ) ;
1565
+ await this . assertUniqueNameWithinPrivateFolder ( newName , file . parentFolderId , driveKey , driveId ) ;
1535
1566
const fileMetadataTxDataStub = await ArFSPrivateFileMetadataTransactionData . from (
1536
1567
newName ,
1537
1568
file . size ,
@@ -1590,6 +1621,7 @@ export class ArDrive extends ArDriveAnonymous {
1590
1621
async renamePublicFolder ( { folderId, newName } : RenamePublicFolderParams ) : Promise < ArFSResult > {
1591
1622
const owner = await this . wallet . getAddress ( ) ;
1592
1623
const folder = await this . getPublicFolder ( { folderId, owner } ) ;
1624
+ const driveId = await this . getDriveIdForFolderId ( folderId ) ;
1593
1625
if ( `${ folder . parentFolderId } ` === ROOT_FOLDER_ID_PLACEHOLDER ) {
1594
1626
throw new Error (
1595
1627
`The root folder with ID '${ folderId } ' cannot be renamed as it shares its name with its parent drive. Consider renaming the drive instead.`
@@ -1599,7 +1631,7 @@ export class ArDrive extends ArDriveAnonymous {
1599
1631
throw new Error ( `New folder name '${ newName } ' must be different from the current folder name!` ) ;
1600
1632
}
1601
1633
assertValidArFSFolderName ( newName ) ;
1602
- await this . assertUniqueNameWithinPublicFolder ( newName , folder . parentFolderId ) ;
1634
+ await this . assertUniqueNameWithinPublicFolder ( newName , folder . parentFolderId , driveId ) ;
1603
1635
const folderMetadataTxDataStub = new ArFSPublicFolderTransactionData ( newName , folder . customMetaDataJson ) ;
1604
1636
1605
1637
const metadataRewardSettings = this . uploadPlanner . isTurboUpload ( )
@@ -1647,6 +1679,7 @@ export class ArDrive extends ArDriveAnonymous {
1647
1679
async renamePrivateFolder ( { folderId, newName, driveKey } : RenamePrivateFolderParams ) : Promise < ArFSResult > {
1648
1680
const owner = await this . wallet . getAddress ( ) ;
1649
1681
const folder = await this . getPrivateFolder ( { folderId, driveKey, owner } ) ;
1682
+ const driveId = await this . getDriveIdForFolderId ( folderId ) ;
1650
1683
if ( `${ folder . parentFolderId } ` === ROOT_FOLDER_ID_PLACEHOLDER ) {
1651
1684
throw new Error (
1652
1685
`The root folder with ID '${ folderId } ' cannot be renamed as it shares its name with its parent drive. Consider renaming the drive instead.`
@@ -1656,7 +1689,7 @@ export class ArDrive extends ArDriveAnonymous {
1656
1689
throw new Error ( `New folder name '${ newName } ' must be different from the current folder name!` ) ;
1657
1690
}
1658
1691
assertValidArFSFolderName ( newName ) ;
1659
- await this . assertUniqueNameWithinPrivateFolder ( newName , folder . parentFolderId , driveKey ) ;
1692
+ await this . assertUniqueNameWithinPrivateFolder ( newName , folder . parentFolderId , driveKey , driveId ) ;
1660
1693
const folderMetadataTxDataStub = await ArFSPrivateFolderTransactionData . from (
1661
1694
newName ,
1662
1695
driveKey ,
0 commit comments