/* * Try to locate in RefSeq Archives: * check for pattern '(\w{4}\d{2})[\.\d]+'; the archive is $1 * use the scheme "x-ncbi-legrefseq" for vfs to recognize special case */ static rc_t SRAPathFullREFSEQArchive(NCBISRAPath const *self, char const rep[], char const vol[], char const accession[], char path[], size_t path_max ) { size_t const rep_sz = strlen(rep); size_t const vol_sz = strlen(vol); char const *const rep_sep = (rep_sz > 0 && rep[rep_sz - 1] != '/') ? "/" : ""; char const *const vol_sep = (vol_sz > 0 && vol[vol_sz - 1] != '/') ? "/" : ""; size_t sz; unsigned i; VFSManager *vfs; rc_t rc = VFSManagerMake(&vfs); VPath *vpath; KDirectory const *dir; KPathType type; if (rc) return rc; for (i = 0; i < 4; ++i) { int const ch = accession[i]; if (ch == 0 || !isalpha(ch)) return RC(rcSRA, rcMgr, rcAccessing, rcPath, rcIncorrect); } for ( ; ; ++i) { int const ch = accession[i]; if (ch == 0) break; if (ch != '.' && !isdigit(ch)) return RC(rcSRA, rcMgr, rcAccessing, rcPath, rcIncorrect); } if (i < 8) return RC(rcSRA, rcMgr, rcAccessing, rcPath, rcIncorrect); rc = string_printf(path, path_max, &sz, "x-ncbi-legrefseq:%s%s%s%s%.6s", rep, rep_sep, vol, vol_sep, accession); if (rc) return rc; i = sz; rc = VPathMake(&vpath, path + 17); if (rc) return rc; rc = VFSManagerOpenDirectoryRead(vfs, &dir, vpath); VPathRelease(vpath); VFSManagerRelease(vfs); if (rc) return rc; type = KDirectoryPathType(dir, "tbl/%s", accession); KDirectoryRelease(dir); if (type != kptDir) return RC(rcSRA, rcMgr, rcAccessing, rcPath, rcIncorrect); rc = string_printf(path + i, path_max - i, &sz, "#tbl/%s", accession); return rc; }
/* ---------------------------------------------------------------------- * SCHEME:PATH/FILE?QUERY * * form_one is just a file * form_two is just a path and a file (can ignore scheme until more schemes supported) * form_three is all parts except path present which for here acts like form_one * form_four is all four parts * * path is the directory path leading to root * root will be the directory containing the archive * base will be the archive as a directory */ static rc_t open_root_then_run () { static const char dot[] = "."; char rootstr [8192]; char basestr [8192]; const char * colon; rc_t rc; colon = strchr (options.arcstr, ':'); if (colon == NULL) /* no scheme so it has to be a plain path */ { char * last_slash; strcpy (basestr, options.arcstr); last_slash = strrchr (basestr, '/'); if (last_slash == NULL) /* in this directory */ { options.rootstr = dot; options.basestr = options.arcstr; /* done */ } else { *last_slash = '\0'; options.rootstr = basestr; options.basestr = last_slash + 1; /* done */ } } else { char * end_of_root; char * last_slash; strcpy (rootstr, colon+1); end_of_root = strchr (rootstr, '?'); if (end_of_root == NULL) end_of_root = strchr (rootstr, '#'); if (end_of_root) *end_of_root = '\0'; options.rootstr = rootstr; last_slash = strchr (rootstr, '/'); if (last_slash == NULL) { /* no path */ options.rootstr = dot; options.basestr = options.arcstr; /* done */ } else { size_t x,z; *last_slash = '\0'; options.rootstr = rootstr; /* scheme */ z = string_size (rootstr); x = string_copy (basestr, sizeof (basestr), options.arcstr, (colon + 1) - options.arcstr); strcpy (basestr + x, options.arcstr + x + z + 1); options.basestr = basestr; /* done */ } } { KDirectory * cwd; rc = VFSManagerGetCWD (options.vfsmgr, &cwd); if (rc) ; else { rc = KDirectoryOpenXTocDirRead (cwd, &options.root, true, options.xml, "%s", options.rootstr); if (rc) PLOGERR (klogErr, (klogErr, rc, "failed to open XFS from '$(P)' using '$(P)'", "P=%s", options.basestr, options.xmlstr)); else { rc = VFSManagerMakePath (options.vfsmgr, &options.basepath, "%s", options.basestr); if (rc) PLOGERR (klogErr, (klogErr, rc, "failed to make vpath from '$(P)'", "P=%s", options.basestr)); else { rc = VFSManagerOpenDirectoryRead (options.vfsmgr, &options.base, options.basepath); if (rc == 0) { rc = build_vpath_then_run (); KDirectoryRelease (options.base); } KDirectoryRelease (options.root); } VPathRelease (options.basepath); } KDirectoryRelease (cwd); } } return rc; }