Skip to content

Commit

Permalink
Add search by meta api to fs interface, and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Mar 23, 2021
1 parent dad6937 commit 56a2665
Show file tree
Hide file tree
Showing 4 changed files with 464 additions and 9 deletions.
73 changes: 73 additions & 0 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ func (fs *FileSystem) List(path string) ([]*FSEntry, error) {
return fs.listEntries(collection.Internal.(*types.IRODSCollection))
}

// SearchByMeta searches all file system entries with given metadata
func (fs *FileSystem) SearchByMeta(metaname string, metavalue string) ([]*FSEntry, error) {
return fs.searchEntriesByMeta(metaname, metavalue)
}

// RemoveDir deletes a directory
func (fs *FileSystem) RemoveDir(path string, recurse bool, force bool) error {
irodsPath := util.GetCorrectIRODSPath(path)
Expand Down Expand Up @@ -908,6 +913,74 @@ func (fs *FileSystem) listEntries(collection *types.IRODSCollection) ([]*FSEntry
return fsEntries, nil
}

func (fs *FileSystem) searchEntriesByMeta(metaName string, metaValue string) ([]*FSEntry, error) {
conn, err := fs.Session.AcquireConnection()
if err != nil {
return nil, err
}
defer fs.Session.ReturnConnection(conn)

collections, err := irods_fs.SearchCollectionsByMeta(conn, metaName, metaValue)
if err != nil {
return nil, err
}

fsEntries := []*FSEntry{}

for _, coll := range collections {
fsEntry := &FSEntry{
ID: coll.ID,
Type: FSDirectoryEntry,
Name: coll.Name,
Path: coll.Path,
Owner: coll.Owner,
Size: 0,
CreateTime: coll.CreateTime,
ModifyTime: coll.ModifyTime,
CheckSum: "",
Internal: coll,
}

fsEntries = append(fsEntries, fsEntry)

// cache it
fs.Cache.AddEntryCache(fsEntry)
}

dataobjects, err := irods_fs.SearchDataObjectsMasterReplicaByMeta(conn, metaName, metaValue)
if err != nil {
return nil, err
}

for _, dataobject := range dataobjects {
if len(dataobject.Replicas) == 0 {
continue
}

replica := dataobject.Replicas[0]

fsEntry := &FSEntry{
ID: dataobject.ID,
Type: FSFileEntry,
Name: dataobject.Name,
Path: dataobject.Path,
Owner: replica.Owner,
Size: dataobject.Size,
CreateTime: replica.CreateTime,
ModifyTime: replica.ModifyTime,
CheckSum: replica.CheckSum,
Internal: dataobject,
}

fsEntries = append(fsEntries, fsEntry)

// cache it
fs.Cache.AddEntryCache(fsEntry)
}

return fsEntries, nil
}

func (fs *FileSystem) getDataObject(path string) (*FSEntry, error) {
// check cache first
cachedEntry := fs.Cache.GetEntryCache(path)
Expand Down
20 changes: 20 additions & 0 deletions fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ func TestListEntries(t *testing.T) {
shutdown()
}

func TestListEntriesByMeta(t *testing.T) {
setup()

entries, err := fs.SearchByMeta("ipc_UUID", "3241af9a-c199-11e5-bd90-3c4a92e4a804")
if err != nil {
t.Errorf("err - %v", err)
panic(err)
}

if len(entries) == 0 {
util.LogDebug("There is no entries")
} else {
for _, entry := range entries {
util.LogDebugf("Entry : %v", entry)
}
}

shutdown()
}

func TestListACLs(t *testing.T) {
setup()

Expand Down
8 changes: 4 additions & 4 deletions irods/fs/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,9 @@ func SearchCollectionsByMeta(conn *connection.IRODSConnection, metaName string,
query.AddSelect(common.ICAT_COLUMN_COLL_MODIFY_TIME, 1)

metaNameCondVal := fmt.Sprintf("= '%s'", metaName)
query.AddCondition(common.ICAT_COLUMN_META_DATA_ATTR_NAME, metaNameCondVal)
query.AddCondition(common.ICAT_COLUMN_META_COLL_ATTR_NAME, metaNameCondVal)
metaValueCondVal := fmt.Sprintf("= '%s'", metaValue)
query.AddCondition(common.ICAT_COLUMN_META_DATA_ATTR_VALUE, metaValueCondVal)
query.AddCondition(common.ICAT_COLUMN_META_COLL_ATTR_VALUE, metaValueCondVal)

queryMessage, err := query.GetMessage()
if err != nil {
Expand Down Expand Up @@ -787,9 +787,9 @@ func SearchCollectionsByMetaWildcard(conn *connection.IRODSConnection, metaName
query.AddSelect(common.ICAT_COLUMN_COLL_MODIFY_TIME, 1)

metaNameCondVal := fmt.Sprintf("= '%s'", metaName)
query.AddCondition(common.ICAT_COLUMN_META_DATA_ATTR_NAME, metaNameCondVal)
query.AddCondition(common.ICAT_COLUMN_META_COLL_ATTR_NAME, metaNameCondVal)
metaValueCondVal := fmt.Sprintf("like '%s'", metaValue)
query.AddCondition(common.ICAT_COLUMN_META_DATA_ATTR_VALUE, metaValueCondVal)
query.AddCondition(common.ICAT_COLUMN_META_COLL_ATTR_VALUE, metaValueCondVal)

queryMessage, err := query.GetMessage()
if err != nil {
Expand Down
Loading

0 comments on commit 56a2665

Please sign in to comment.