@@ -14,6 +14,7 @@ import (
14
14
"github.com/cyverse/go-irodsclient/irods/message"
15
15
"github.com/cyverse/go-irodsclient/irods/types"
16
16
"github.com/cyverse/go-irodsclient/irods/util"
17
+ "github.com/danwakefield/fnmatch"
17
18
"golang.org/x/xerrors"
18
19
)
19
20
@@ -1274,8 +1275,8 @@ func ListDataObjectsMasterReplica(conn *connection.IRODSConnection, collection *
1274
1275
return mergedDataObjects , nil
1275
1276
}
1276
1277
1277
- // SearchDataObjects searches data objects in the given collection using wildcard
1278
- func SearchDataObjects (conn * connection.IRODSConnection , pathWildcard string ) ([]* types.IRODSDataObject , error ) {
1278
+ // SearchDataObjectsUnixWildcard searches data objects in the given collection using unix-style wildcard
1279
+ func SearchDataObjectsUnixWildcard (conn * connection.IRODSConnection , pathUnixWildcard string ) ([]* types.IRODSDataObject , error ) {
1279
1280
if conn == nil || ! conn .IsConnected () {
1280
1281
return nil , xerrors .Errorf ("connection is nil or disconnected" )
1281
1282
}
@@ -1285,10 +1286,10 @@ func SearchDataObjects(conn *connection.IRODSConnection, pathWildcard string) ([
1285
1286
metrics .IncreaseCounterForList (1 )
1286
1287
}
1287
1288
1288
- pathWildcard = util .UnixWildcardsToSQLWildcards (pathWildcard )
1289
+ pathUnixWildcard = util .UnixWildcardsToSQLWildcards (pathUnixWildcard )
1289
1290
// we don't use util.GetBasename() and util.GetDir() as wildcard may have '\' in the path
1290
- basenameSqlWildcard := path .Base (pathWildcard )
1291
- dirnameSqlWildcard := path .Dir (pathWildcard )
1291
+ basenameSqlWildcard := path .Base (pathUnixWildcard )
1292
+ dirnameSqlWildcard := path .Dir (pathUnixWildcard )
1292
1293
1293
1294
// lock the connection
1294
1295
conn .Lock ()
@@ -1413,7 +1414,6 @@ func SearchDataObjects(conn *connection.IRODSConnection, pathWildcard string) ([
1413
1414
}
1414
1415
case int (common .ICAT_COLUMN_COLL_NAME ):
1415
1416
pagenatedDataObjectCollectionNames [row ] = value
1416
-
1417
1417
if len (pagenatedDataObjects [row ].Name ) > 0 {
1418
1418
pagenatedDataObjects [row ].Path = util .MakeIRODSPath (value , pagenatedDataObjects [row ].Name )
1419
1419
}
@@ -1465,7 +1465,13 @@ func SearchDataObjects(conn *connection.IRODSConnection, pathWildcard string) ([
1465
1465
}
1466
1466
}
1467
1467
1468
- dataObjects = append (dataObjects , pagenatedDataObjects ... )
1468
+ // Filter results by original unix wildcard, since the SQL wildcards
1469
+ // are less strict (e.g. a unix wildcard range is converted to a generic wildcards in SQL).
1470
+ for _ , pagenatedDataObject := range pagenatedDataObjects {
1471
+ if fnmatch .Match (pathUnixWildcard , pagenatedDataObject .Path , fnmatch .FNM_PATHNAME ) {
1472
+ dataObjects = append (dataObjects , pagenatedDataObject )
1473
+ }
1474
+ }
1469
1475
1470
1476
continueIndex = queryResult .ContinueIndex
1471
1477
if continueIndex == 0 {
@@ -1495,8 +1501,8 @@ func SearchDataObjects(conn *connection.IRODSConnection, pathWildcard string) ([
1495
1501
return mergedDataObjects , nil
1496
1502
}
1497
1503
1498
- // SearchDataObjectsMasterReplica searches data objects in the given collection using wildcard, returns only master replica
1499
- func SearchDataObjectsMasterReplica (conn * connection.IRODSConnection , pathWildcard string ) ([]* types.IRODSDataObject , error ) {
1504
+ // SearchDataObjectsMasterReplicaUnixWildcard searches data objects in the given collection using unix-style wildcard, returns only master replica
1505
+ func SearchDataObjectsMasterReplicaUnixWildcard (conn * connection.IRODSConnection , pathUnixWildcard string ) ([]* types.IRODSDataObject , error ) {
1500
1506
if conn == nil || ! conn .IsConnected () {
1501
1507
return nil , xerrors .Errorf ("connection is nil or disconnected" )
1502
1508
}
@@ -1506,10 +1512,10 @@ func SearchDataObjectsMasterReplica(conn *connection.IRODSConnection, pathWildca
1506
1512
metrics .IncreaseCounterForList (1 )
1507
1513
}
1508
1514
1509
- pathWildcard = util .UnixWildcardsToSQLWildcards (pathWildcard )
1515
+ pathUnixWildcard = util .UnixWildcardsToSQLWildcards (pathUnixWildcard )
1510
1516
// we don't use util.GetBasename() and util.GetDir() as wildcard may have '\' in the path
1511
- basenameSqlWildcard := path .Base (pathWildcard )
1512
- dirnameSqlWildcard := path .Dir (pathWildcard )
1517
+ basenameSqlWildcard := path .Base (pathUnixWildcard )
1518
+ dirnameSqlWildcard := path .Dir (pathUnixWildcard )
1513
1519
1514
1520
// lock the connection
1515
1521
conn .Lock ()
@@ -1635,7 +1641,6 @@ func SearchDataObjectsMasterReplica(conn *connection.IRODSConnection, pathWildca
1635
1641
}
1636
1642
case int (common .ICAT_COLUMN_COLL_NAME ):
1637
1643
pagenatedDataObjectCollectionNames [row ] = value
1638
-
1639
1644
if len (pagenatedDataObjects [row ].Name ) > 0 {
1640
1645
pagenatedDataObjects [row ].Path = util .MakeIRODSPath (value , pagenatedDataObjects [row ].Name )
1641
1646
}
@@ -1687,7 +1692,13 @@ func SearchDataObjectsMasterReplica(conn *connection.IRODSConnection, pathWildca
1687
1692
}
1688
1693
}
1689
1694
1690
- dataObjects = append (dataObjects , pagenatedDataObjects ... )
1695
+ // Filter results by original unix wildcard, since the SQL wildcards
1696
+ // are less strict (e.g. a unix wildcard range is converted to a generic wildcards in SQL).
1697
+ for _ , pagenatedDataObject := range pagenatedDataObjects {
1698
+ if fnmatch .Match (pathUnixWildcard , pagenatedDataObject .Path , fnmatch .FNM_PATHNAME ) {
1699
+ dataObjects = append (dataObjects , pagenatedDataObject )
1700
+ }
1701
+ }
1691
1702
1692
1703
continueIndex = queryResult .ContinueIndex
1693
1704
if continueIndex == 0 {
0 commit comments