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; }
static rc_t nenctool (const char * srcstr, const char * dststr, bool force) { VFSManager * mgr; rc_t rc; rc = VFSManagerMake (&mgr); if (rc) LOGERR (klogInt, rc, "failed to create file system manager"); else { VPath * srcpath; rc = VFSManagerMakePath (mgr, &srcpath, "%s", srcstr); if (rc) PLOGERR (klogErr, (klogErr, rc, "Failed to parse source path '$(path)'", "path=%s", srcstr)); else { VPath * dstpath; rc = VFSManagerMakePath (mgr, &dstpath, "%s", dststr); if (rc) PLOGERR (klogErr, (klogErr, rc, "Failed to parse destination path '$(path)'", "path=%s", dststr)); else { const KFile * srcfile; rc = VFSManagerOpenFileRead (mgr, &srcfile, srcpath); if (rc) PLOGERR (klogErr, (klogErr, rc, "Failed to open source path '$(path)'", "path=%s", srcstr)); else { KFile * dstfile; rc = VFSManagerCreateFile (mgr, &dstfile, false, 0666, kcmParents | (force ? kcmInit : kcmCreate), dstpath); if (rc) PLOGERR (klogErr, (klogErr, rc, "failed to open destination path '$(path)'", "path=%s", dststr)); else { rc = copy_file (srcstr, dststr, srcfile, dstfile); if (rc) { PLOGERR (klogErr, (klogErr, rc, "failed to copy '$(S)' to '$(D)'", "S=%s,D=%s", srcstr, dststr)); VFSManagerRemove (mgr, true, dstpath); } KFileRelease (dstfile); } KFileRelease (srcfile); } VPathRelease (dstpath); } VPathRelease (srcpath); } VFSManagerRelease (mgr); } return rc; }