diff --git a/sda/cmd/mapper/mapper.go b/sda/cmd/mapper/mapper.go index a7455342f..dcf6d0df1 100644 --- a/sda/cmd/mapper/mapper.go +++ b/sda/cmd/mapper/mapper.go @@ -9,6 +9,7 @@ import ( "github.com/neicnordic/sensitive-data-archive/internal/broker" "github.com/neicnordic/sensitive-data-archive/internal/config" "github.com/neicnordic/sensitive-data-archive/internal/database" + "github.com/neicnordic/sensitive-data-archive/internal/helper" "github.com/neicnordic/sensitive-data-archive/internal/schema" "github.com/neicnordic/sensitive-data-archive/internal/storage" @@ -102,14 +103,14 @@ func main() { } for _, aID := range mappings.AccessionIDs { - log.Debugf("Mapped file to dataset (corr-id: %s, datasetid: %s, accessionid: %s)", delivered.CorrelationId, mappings.DatasetID, aID) - filePath, err := db.GetInboxPath(aID) + fileInfo, err := db.GetFileInfoFromAccessionID(aID) if err != nil { - log.Errorf("failed to get inbox path for file with stable ID: %s", aID) + log.Errorf("failed to get file info for file with stable ID: %s", aID) } - err = inbox.RemoveFile(filePath) + + err = inbox.RemoveFile(helper.UnanonymizeFilepath(fileInfo.FilePath, fileInfo.User)) if err != nil { - log.Errorf("Remove file from inbox failed, reason: %v", err) + log.Errorf("Remove file from inbox %s failed, reason: %v", fileInfo.FilePath, err) } } diff --git a/sda/internal/database/db_functions.go b/sda/internal/database/db_functions.go index bf8843db7..3df680031 100644 --- a/sda/internal/database/db_functions.go +++ b/sda/internal/database/db_functions.go @@ -516,6 +516,39 @@ func (dbs *SDAdb) GetHeaderForStableID(stableID string) ([]byte, error) { return header, nil } +// GetFileInfoFromAccessionID retrieves the file information needed for mapping +func (dbs *SDAdb) GetFileInfoFromAccessionID(accessionID string) (SyncData, error) { + var ( + s SyncData + err error + ) + + for count := 1; count <= RetryTimes; count++ { + s, err = dbs.getFileInfoFromAccessionID(accessionID) + if err == nil { + break + } + time.Sleep(time.Duration(math.Pow(3, float64(count))) * time.Second) + } + + return s, err +} + +// getFileInfoFromAccessionID is the actual function performing work for GetFileInfoFromAccessionID +func (dbs *SDAdb) getFileInfoFromAccessionID(accessionID string) (SyncData, error) { + dbs.checkAndReconnectIfNeeded() + + const query = "SELECT submission_user, submission_file_path from sda.files WHERE stable_id = $1;" + var data SyncData + if err := dbs.DB.QueryRow(query, accessionID).Scan(&data.User, &data.FilePath); err != nil { + log.Warnf("Error while searching for id %s: %v", accessionID, err) + + return SyncData{}, err + } + + return data, nil +} + // GetSyncData retrieves the file information needed to sync a dataset func (dbs *SDAdb) GetSyncData(accessionID string) (SyncData, error) { var (