static rc_t run (void) { VFSManager * manager; rc_t rc = 0, orc = 0; STSMSG (1, ("Make VFSManager")); rc = VFSManagerMake (&manager); STSMSG (2, ("rc %R", orc, orc)); if (rc == 0) { #if 1 static const char name[] = "test-kfs-manager-data-file"; #else static const char name[] = "ncbi-kfs:test-kfs-manager-data-file?enc&pwfile=password"; #endif VPath * path; STSMSG (1, ("Make test VPath file '%s'",name)); rc = VPathMake (&path, name); STSMSG (2, ("rc %R", orc, orc)); if (rc == 0) { KFile * file; STSMSG (1, ("Open File for write using manager and path")); rc = VFSManagerCreateFile (manager, &file, false, 0666, kcmCreate, path); STSMSG (2, ("rc %R", rc, rc)); if (rc == 0) { char buff[4096]; size_t ix; size_t num_writ; uint64_t tot_writ = 0; for (ix = 0; ix < sizeof buff; ++ix) buff[ix] = 'A' + (ix%26); STSMSG (1, ("writing to file")); for (ix = 0; ix < 32; ++ix) { rc = KFileWrite (file, tot_writ, buff, sizeof buff, &num_writ); if (rc == 0) tot_writ += num_writ; }; STSMSG (1, ("Release file - it should whack")); orc = KFileRelease (file); STSMSG (2, ("rc %R", orc, orc)); if (rc == 0) rc = orc; #if 1 STSMSG (1, ("Remove file")); orc = VFSManagerRemove (manager, true, path); STSMSG (2, ("rc %R", orc, orc)); if (rc == 0) rc = orc; #endif } STSMSG (1, ("Release VPath - it should Whack")); orc = VPathRelease (path); STSMSG (2, ("rc %R", orc, orc)); if (rc == 0) rc = orc; } STSMSG (1, ("Release VFSManager - it should Whack")); orc = VFSManagerRelease (manager); STSMSG (2, ("rc %R", orc, orc)); if (rc == 0) rc = orc; } return rc; }
/* * 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; }