void sendFileByAcc(struct sqlConnection *conn, char* acc) /* send file identified by acc (=cdwValidFile.licensePlate), suggests a canonical filename of the format * <licensePlate>.<originalExtension> * Example URL: http://hgwdev.soe.ucsc.edu/cgi-bin/cdwGetFile?acc=SCH000FSW */ { struct cdwValidFile *vf = cdwValidFileFromLicensePlate(conn, acc); if (vf==NULL) errExit("%s is not a valid accession in the CDW.", acc); struct cdwFile *ef = cdwFileFromId(conn, vf->fileId); char* filePath = cdwPathForFileId(conn, vf->fileId); mustHaveAccess(conn, ef); // use the license plate as the basename of the downloaded file. // Take the extension from the submitted filename, as cdwFile.format is not the same as the extension // e.g. format=fasta -> fa.gz char *submitExt = skipBeyondDelimit(basename(ef->submitFileName), '.'); char suggestName[8000]; safef(suggestName, sizeof(suggestName), "%s.%s", vf->licensePlate, submitExt); apacheSendX(vf->format, filePath, suggestName); }
void cdwGroupFile(char *groupName, char *where) /* cdwGroupFile - Associate a file with a group.. */ { /* Get group from database, error out if no good */ struct sqlConnection *conn = cdwConnectReadWrite(); struct cdwGroup *group = cdwNeedGroupFromName(conn, groupName); /* Get list of all stanzas matching query */ struct tagStorm *tags = cdwTagStorm(conn); struct dyString *rqlQuery = dyStringNew(0); dyStringPrintf(rqlQuery, "select accession from cdwFileTags where accession"); if (where != NULL) dyStringPrintf(rqlQuery, " and %s", where); struct slRef *ref, *matchRefList = tagStanzasMatchingQuery(tags, rqlQuery->string); /* Make one pass through mostly for early error reporting and building up * hash of cdwValidFiles keyed by accession */ struct hash *validHash = hashNew(0); for (ref = matchRefList; ref != NULL; ref = ref->next) { struct tagStanza *stanza = ref->val; char *acc = tagFindVal(stanza, "accession"); if (acc != NULL) { struct cdwValidFile *vf = cdwValidFileFromLicensePlate(conn, acc); if (vf == NULL) errAbort("%s not found in cdwValidFile", acc); hashAdd(validHash, acc, vf); } } /* Second pass through matching list we call routine that actually adds * the group/file relationship. */ for (ref = matchRefList; ref != NULL; ref = ref->next) { struct tagStanza *stanza = ref->val; char *acc = tagFindVal(stanza, "accession"); if (acc != NULL) { struct cdwValidFile *vf = hashFindVal(validHash, acc); if (vf != NULL) { addGroupToValidFile(conn, vf, group); } } } if (clDry) verbose(1, "Would have %s", (clRemove ? "removed" : "added")); else verbose(1, "%s", (clRemove ? "Removed" : "Added")); verbose(1, " group %s to %d files\n", group->name, validHash->elCount); }
void cdwChangeAccess(char *chmodString, char *rqlWhere) /* cdwChangeAccess - Change access to files.. */ { char cWhere, cDir, cAccess; parseChmodString(chmodString, &cWhere, &cDir, &cAccess); /* Get list of all stanzas matching query */ struct sqlConnection *conn = cdwConnectReadWrite(); struct tagStorm *tags = cdwTagStorm(conn); struct dyString *rqlQuery = dyStringNew(0); dyStringPrintf(rqlQuery, "select accession from cdwFileTags where accession and %s", rqlWhere); struct slRef *ref, *matchRefList = tagStanzasMatchingQuery(tags, rqlQuery->string); /* Make one pass through mostly for early error reporting and building up * hash of cdwValidFiles keyed by accession */ struct hash *validHash = hashNew(0); for (ref = matchRefList; ref != NULL; ref = ref->next) { struct tagStanza *stanza = ref->val; char *acc = tagFindVal(stanza, "accession"); if (acc != NULL) { struct cdwValidFile *vf = cdwValidFileFromLicensePlate(conn, acc); if (vf == NULL) errAbort("%s not found in cdwValidFile", acc); hashAdd(validHash, acc, vf); } } /* Second pass through matching list we call routine that actually adds * the group/file relationship. */ for (ref = matchRefList; ref != NULL; ref = ref->next) { struct tagStanza *stanza = ref->val; char *acc = tagFindVal(stanza, "accession"); if (acc != NULL) { struct cdwValidFile *vf = hashFindVal(validHash, acc); if (vf != NULL) { changeAccess(conn, vf->fileId, cWhere, cDir, cAccess); } } } }