Пример #1
0
static void ensureTmpDirExists() {
  if (saveCDir[0] == '\0') {
    if (tmpdirname == NULL) {
      tmpdirname = makeTempDir("chpl-");
      intDirName = tmpdirname;
    }
  } else {
    if (intDirName != saveCDir) {
      intDirName = saveCDir;
      ensureDirExists(saveCDir, "ensuring --savec directory exists");
    }
  }
}
Пример #2
0
TEST_F(TestFileCache, AutodetectNewCache) {
  // Make a quick new cache file on disk.
  CacheManager cm;
  ASSERT_TRUE(cm.addEmptyEntry("test_entry"));

  string temp_dir;
  ASSERT_TRUE(makeTempDir(&temp_dir));

  string cache_fn(temp_dir);
  cache_fn.append("/cache.dump");

  ASSERT_TRUE(cm.saveCache(cache_fn));

  // Now make sure this file-cache is in default mode.
  FileCache fc;
  FileCache::UseNewCache = false;

  fc.loadMmap(cache_fn.c_str(), 1);
  ASSERT_TRUE(fc.exists("test_entry"));
}
void runSlam(char *chrNibDir, char *alignNibDir, char *outputDir, char *refPrefix, char *alignPrefix,  char *pos, char **alignBits, int numAlignBits)
/* Top level function. Pipeline is to cut out genome bits, order and orient using avid, align merged using avid, then run slam. */
{
char *tmpDir = NULL;
struct genomeBit *target = parseGenomeBit(pos);
struct genomeBit *aligns = parseGenomeBits(alignBits, numAlignBits);
char *fa1 = NULL;
char *fa2 = NULL;
char *gff1 = NULL;
char *gff2 = NULL;
char buff[4096];
char cwdBuff[4096];
char *cwd = NULL;
int fileNo = 0, stderrNo = 0, stdoutNo =0;
FILE *logFile = NULL;
char *host = NULL;

/* quick hack to reverse args for slam.pl */
if(sameString(refPrefix, "mm"))
    slamOpts = " --org1 M.musculus --org2 H.sapiens ";
else
    slamOpts = "";

/* create file names we're going to be using */
fa1 = fileNameFromGenomeBit("", ".fa", target);
fa2 = fileNameFromGenomeBit("", ".fa", aligns);
gff1 = fileNameFromGenomeBit("", "", target);
gff2 = fileNameFromGenomeBit("", "", aligns);
runAvidFirst = TRUE;  /* Run avid to order and orient before using to align. */

/* We're going to create a temporary working directory and move the program there. */
tmpDir = slamTempName("/tmp", "slam", "/");
outputRoot = tmpDir;
makeTempDir();
cwd = getcwd(cwdBuff, ArraySize(cwdBuff));
assert(cwd);
chdir(outputRoot);
snprintf(buff, sizeof(buff), "%s/%s.%s_%s.%s.log", outputDir, refPrefix, gff1, alignPrefix, gff2);
logFile = mustOpen(buff, "w");
fileNo = fileno(logFile);
stderrNo = fileno(stderr);
stdoutNo = fileno(stdout);
setbuf(logFile, NULL);
/* pipe both stderr and stdout to our logfile. */
dup2(fileNo, stderrNo);
dup2(fileNo,stdoutNo);

/* little debugging info */
host = slamGetHost();
warn("Host is: %s", host);
warn("creating %s", target->chrom);

/* create fasta files and run slam.pl on them. */
createFastaFilesForBits(chrNibDir, target, FALSE); 
warn("creating %s", aligns->chrom); 
createFastaFilesForBits(alignNibDir, aligns, TRUE);
warn("running slam"); 
runSlamExe(outputDir,target, aligns, refPrefix, alignPrefix);
warn("removing stuff"); 

/* Cleanup. */
carefulClose(&logFile);
chdir(cwd);
removeTempDir(target, aligns);
genomeBitFreeList(&target);
genomeBitFreeList(&aligns);
}
Пример #4
0
int main(int argc, char **argv)
{
	int correctAddDelete = 0;

	if(argIs("/CAD")) // Correct Add Delete
	{
		correctAddDelete = 1;
	}

	if(argIs("/M")) // Make sabun
	{
		char *beforeDir;
		char *afterDir;
		char *outDir;
		char *sabunFile;

		cout("+----------------------------+\n");
		cout("| 変更前のフォルダをドロップ |\n");
		cout("+----------------------------+\n");
		beforeDir = dropDir();

		cout("+----------------------------+\n");
		cout("| 変更後のフォルダをドロップ |\n");
		cout("+----------------------------+\n");
		afterDir = dropDir();

		outDir = makeTempDir(NULL);
		sabunFile = combine(outDir, "Sabun.bin");

		makeSabun(sabunFile, beforeDir, afterDir, correctAddDelete);

		execute_x(xcout("START %s", outDir));

		memFree(beforeDir);
		memFree(afterDir);
		memFree(outDir);
		memFree(sabunFile);
	}
	else // 差分適用
	{
		char *targetDir;
		char *sabunFile;

		cout("+----------------------------------+\n");
		cout("| 対象フォルダをドロップ           |\n");
		cout("| * このフォルダの中身を更新します |\n");
		cout("+----------------------------------+\n");
		targetDir = dropDir();

		cout("+------------------------+\n");
		cout("| 差分ファイルをドロップ |\n");
		cout("+------------------------+\n");
		sabunFile = dropFile();

		cout("\n");
		cout("対象フォルダを変更します。\n");
		cout("処理を開始してからはキャンセル出来ません。\n");
		cout("続行するにはエンターキーを押してね。\n");

		if(clearGetKey() == 0x0d)
		{
			cout("\n");
			cout("アップデートしています...");

			if(sabunUpdate(sabunFile, targetDir) == 0) // ? アップデート対象外だった。
			{
				cout("\r");
				cout("+----------------------------+\n");
				cout("| エラー/アップデート対象外 |\n");
				cout("+----------------------------+\n");
			}
			else
				cout("\rアップデートは完了しました。\n");

			clearWaitKey(5000); // 見えるように
		}
		memFree(targetDir);
		memFree(sabunFile);
	}
}
Пример #5
0
TEST_F(TestFileCache, WriteAndReadBack) {
  // Set up something for FileCache to read in.

  char data_fn[] = "/tmp/hhvm_unit_test-testdata.XXXXXX";
  int data_fd = mkstemp(data_fn);
  ASSERT_GT(data_fd, 0);

  FILE* f = fdopen(data_fd, "w");
  ASSERT_TRUE(f != nullptr);

  fprintf(f, "%s", kTestData);
  fclose(f);

  // Set up a cache and put this data file in it.

  FileCache fc;
  fc.write("_unit_test_one_", data_fn);
  fc.write("_unit_test_two_");
  fc.write("/__invalid__/path/with/directories");

  std::string temp_dir;
  ASSERT_TRUE(makeTempDir(&temp_dir));

  std::string cache_fn(temp_dir);
  cache_fn.append("/cache.dump");

  // Flush to disk.

  fc.save(cache_fn.c_str());

  // Read back into another cache.

  FileCache fc2;
  fc2.loadMmap(cache_fn.c_str());

  EXPECT_TRUE(fc2.fileExists("_unit_test_one_"));

  int read_len;
  bool compressed = false;
  const char* read_data = fc2.read("_unit_test_one_", read_len, compressed);

  EXPECT_STREQ(kTestData, read_data);
  EXPECT_EQ(fc2.fileSize("_unit_test_one_", false), strlen(kTestData));

  EXPECT_TRUE(fc2.fileExists("_unit_test_two_"));
  EXPECT_FALSE(fc2.fileExists("_unit_test_three_"));

  EXPECT_TRUE(fc2.dirExists("/__invalid__"));
  EXPECT_TRUE(fc2.dirExists("/__invalid__/path"));
  EXPECT_TRUE(fc2.dirExists("/__invalid__/path/with"));
  EXPECT_TRUE(fc2.fileExists("/__invalid__/path/with/directories"));

  // -1 is a magic value... here it means "it's a PHP file"...
  EXPECT_EQ(fc2.fileSize("unit_test_two_", false), -1);

  // ... and here it means "this thing does not exist".
  EXPECT_EQ(fc2.fileSize("unit_test_three_", false), -1);

  fc2.dump();

  // Clean up the mess.

  ASSERT_EQ(unlink(cache_fn.c_str()), 0);
  ASSERT_EQ(rmdir(temp_dir.c_str()), 0);
  ASSERT_EQ(unlink(data_fn), 0);
}
Пример #6
0
TEST_F(TestFileCache, HighlyCompressibleData) {
  char data_fn[] = "/tmp/hhvm_unit_test-testdata.XXXXXX";
  int data_fd = mkstemp(data_fn);
  ASSERT_GT(data_fd, 0);

  FILE* f = fdopen(data_fd, "w");
  ASSERT_TRUE(f != nullptr);

  std::string test_path = "/path/to/data";
  std::string test_data;

  for (int i = 0; i < 10; ++i) {
    test_data.append("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
  }

  fprintf(f, "%s", test_data.c_str());
  fclose(f);

  FileCache fc;
  fc.write(test_path.c_str(), data_fn);

  // Flush to disk.

  std::string temp_dir;
  ASSERT_TRUE(makeTempDir(&temp_dir));

  std::string cache_fn(temp_dir);
  cache_fn.append("/cache.dump");

  fc.save(cache_fn.c_str());

  // Read back into another cache.

  int read_len;
  bool compressed;
  const char* read_data;

  FileCache fc3;
  fc3.loadMmap(cache_fn.c_str());
  fc3.dump();

  ASSERT_TRUE(fc3.fileExists(test_path.c_str()));

  // Ask for uncompressed data (a holdover from the original API).
  compressed = false;
  read_data = fc3.read(test_path.c_str(), read_len, compressed);

  // FileCache::read() takes compressed as a non-const reference (!)
  // and changes the value according to what it found...

  // ... so this means "I just gave you compressed data".
  EXPECT_TRUE(compressed);

  // ... so these can't match.
  EXPECT_NE(test_data, read_data);
  EXPECT_NE(test_data.length(), read_len);

  // But this always gets the uncompressed size no matter what.
  EXPECT_EQ(test_data.length(), fc3.fileSize(test_path.c_str(), false));

  // So now let's actually ask for compressed data this time.
  compressed = true;
  read_data = fc3.read(test_path.c_str(), read_len, compressed);

  // Same conditions should hold.
  EXPECT_TRUE(compressed);
  EXPECT_NE(test_data, read_data);
  EXPECT_EQ(test_data.length(), fc3.fileSize(test_path.c_str(), false));

  // Clean up the mess.

  ASSERT_EQ(unlink(cache_fn.c_str()), 0);
  ASSERT_EQ(rmdir(temp_dir.c_str()), 0);
  ASSERT_EQ(unlink(data_fn), 0);
}