Instance::Instance(const wxString &rootDir) : modList(this), m_running(false) { if (!rootDir.EndsWith("/")) this->rootDir = wxFileName::DirName(rootDir + "/"); else this->rootDir = wxFileName::DirName(rootDir); config = new wxFileConfig(wxEmptyString, wxEmptyString, GetConfigPath().GetFullPath(), wxEmptyString, wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH); evtHandler = NULL; MkDirs(); // initialize empty mod lists - they are filled later and only if requested (see apropriate Get* methods) modList.SetDir(GetInstModsDir().GetFullPath()); mlModList.SetDir(GetMLModsDir().GetFullPath()); coreModList.SetDir(GetCoreModsDir().GetFullPath()); worldList.SetDir(GetSavesDir().GetFullPath()); tpList.SetDir(GetTexturePacksDir().GetFullPath()); modloader_list_inited = false; coremod_list_inited = false; jar_list_inited = false; world_list_initialized = false; tp_list_initialized = false; parentModel = nullptr; UpdateVersion(); }
/** * @brief test the partition file */ void testTraverseChild4PartitionFile() { deleteTmpFiles("./test-result/"); exists = file_dir_exists("./test-result/"); Filename = "../test-data/testdata4unpack/vmlinuz-2.6.26-2-686"; MkDirs("./test-result/vmlinuz-2.6.26-2-686.dir/"); strcpy(Queue[0].ChildRecurse, "./test-result/vmlinuz-2.6.26-2-686.dir/"); lstat(Filename, &Stat); ContainerInfo CITemp; memset(&CITemp,0,sizeof(ContainerInfo)); strcpy(CITemp.Source, Filename); strcpy(CITemp.Partdir, NewDir); strcpy(CITemp.Partname, "vmlinuz-2.6.26-2-686"); strcpy(CITemp.PartnameNew, "vmlinuz-2.6.26-2-686"); ParentInfo PITemp = {26, 1287725739, 1287725739, 0}; lstat(Filename, &Stat); CITemp.Stat = Stat; CITemp.PI = PITemp; int Pid; Pid = fork(); if (Pid == 0) { TraverseChild(Index, &CITemp, NewDir); } else { ParentWait(); exists = file_dir_exists("./test-result/vmlinuz-2.6.26-2-686.dir/Partition_0000"); FO_ASSERT_EQUAL(exists, 1); // existing } }
Instance::Instance(const wxFileName &rootDir) { this->rootDir = rootDir; config = new wxFileConfig(wxEmptyString, wxEmptyString, GetConfigPath().GetFullPath(), wxEmptyString, wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH); evtHandler = NULL; MkDirs(); UpdateModList(); LoadMLModList(); }
/** * @brief abnormal parameters */ void testExtractAR4ErrorParameters() { deleteTmpFiles("./test-result/"); exists = file_dir_exists("./test-result/"); FO_ASSERT_EQUAL(exists, 0); // not existing MkDirs("./test-result/fossology-1.2.0-1.el5.i386.rpm.dir/"); Filename = "../test-data/testdata4unpack/fossology-1.2.0-1.el5.i386.rpm"; Result = ExtractAR(Filename, "./test-result/fossology-1.2.0-1.el5.i386.rpm.dir"); FO_ASSERT_EQUAL(Result, 1); // fail to Extract archieve library }
/** * @brief ununpack iso file */ void testTraverseChild4IsoFile() { deleteTmpFiles("./test-result/"); exists = file_dir_exists("./test-result/"); Filename = "../test-data/testdata4unpack/imagefile.iso"; MkDirs("./test-result/imagefile.iso.dir/"); lstat(Filename, &Stat); ContainerInfo CITemp; memset(&CITemp,0,sizeof(ContainerInfo)); strcpy(CITemp.Source, Filename); strcpy(CITemp.Partdir, NewDir); strcpy(CITemp.Partname, "imagefile.iso"); strcpy(CITemp.PartnameNew, "imagefile.iso.dir"); CITemp.Stat = Stat; CITemp.PI.Cmd = 20; CITemp.PI.StartTime = 1287725739; CITemp.PI.EndTime = 1287725739; CITemp.PI.ChildRecurseArtifact = 0; CITemp.uploadtree_pk = 0; CITemp.Artifact = 0; CITemp.IsDir = 0; CITemp.IsCompressed = 0; CITemp.uploadtree_pk = 0; CITemp.pfile_pk = 0; CITemp.ufile_mode = 0; strcpy(Queue[0].ChildRecurse, "./test-result/imagefile.iso.dir"); /* test TraverseChild */ int Pid; Pid = fork(); if (Pid == 0) { TraverseChild(Index, &CITemp, NewDir); } else { ParentWait(); int rc = 0; char commands[250]; sprintf(commands, "isoinfo -f -R -i '%s' | grep ';1' > /dev/null ", Filename); rc = system(commands); if (0 != rc) { exists = file_dir_exists("./test-result/imagefile.iso.dir/test.jar"); FO_ASSERT_EQUAL(exists, 1); // existing exists = file_dir_exists("./test-result/imagefile.iso.dir/test.jar.dir"); FO_ASSERT_EQUAL(exists, 0); // not existing } else { exists = file_dir_exists("./test-result/imagefile.iso.dir/TEST.JAR;1"); FO_ASSERT_EQUAL(exists, 1); // existing } } }
/** * @brief unpack disk image, ntfs */ void testExtractDisk4Ntfs() { deleteTmpFiles("./test-result/"); exists = file_dir_exists("./test-result/"); FO_ASSERT_EQUAL(exists, 0); // not existing Filename = "../test-data/testdata4unpack/ntfstest-image"; MkDirs("./test-result/ntfstest-image.dir"); Result = ExtractDisk(Filename, "ntfs", "./test-result/ntfstest-image.dir"); exists = file_dir_exists("./test-result/ntfstest-image.dir/ununpack.c"); FO_ASSERT_EQUAL(Result, 0); FO_ASSERT_EQUAL(exists, 1); }
/** * @brief unpack disk image, ext2, FStype is unknowed */ void testExtractDisk4Ext2FstypeUnknow() { deleteTmpFiles("./test-result/"); exists = file_dir_exists("./test-result/"); FO_ASSERT_EQUAL(exists, 0); // not existing Filename = "../test-data/testdata4unpack/ext2test-image"; MkDirs("./test-result/ext2test-image.dir"); Result = ExtractDisk(Filename, "", "./test-result/ext2test-image.dir"); exists = file_dir_exists("./test-result/ext2test-image.dir/ununpack.c"); FO_ASSERT_EQUAL(Result, 1); FO_ASSERT_EQUAL(exists, 0); }
/** * @brief unpack disk image, ext3 */ void testExtractDisk4Ext3() { deleteTmpFiles("./test-result/"); exists = file_dir_exists("./test-result/"); FO_ASSERT_EQUAL(exists, 0); // not existing Filename = "../test-data/testdata4unpack/ext3test-image"; MkDirs("./test-result/ext3test-image.dir"); Result = ExtractDisk(Filename, "ext", "./test-result/ext3test-image.dir"); exists = file_dir_exists("./test-result/ext3test-image.dir/libfossagent.a"); FO_ASSERT_EQUAL(Result, 0); FO_ASSERT_EQUAL(exists, 1); }
/** * @brief unpack deb file */ void testExtractAR4DebFile() { deleteTmpFiles("./test-result/"); exists = file_dir_exists("./test-result/"); FO_ASSERT_EQUAL(exists, 0); // not existing MkDirs("./test-result/bind9-host_1%3a9.7.0.dfsg.P1-1_i386.deb.dir/"); Filename = "../test-data/testdata4unpack/bind9-host_1%3a9.7.0.dfsg.P1-1_i386.deb"; Result = ExtractAR(Filename, "./test-result/bind9-host_1%3a9.7.0.dfsg.P1-1_i386.deb.dir"); exists = file_dir_exists("./test-result/bind9-host_1%3a9.7.0.dfsg.P1-1_i386.deb.dir/data.tar.gz"); FO_ASSERT_EQUAL(exists, 1); // existing FO_ASSERT_EQUAL(Result, 0); // Extract archieve library successfully }
/** @brief unpack archive library file **/ void testExtractAR4ArchiveLibraryFile() { deleteTmpFiles("./test-result/"); exists = file_dir_exists("./test-result/"); FO_ASSERT_EQUAL(exists, 0); // not existing MkDirs("./test-result/libfossagent.a.dir/"); Filename = "../test-data/testdata4unpack/libfossagent.a"; Result = ExtractAR(Filename, "./test-result/libfossagent.a.dir"); exists = file_dir_exists("./test-result/libfossagent.a.dir/libfossagent.o"); FO_ASSERT_EQUAL(exists, 1); // existing FO_ASSERT_EQUAL(Result, 0); // Extract archieve library successfully }
int MkSpoolDir(char *sdir, size_t size) { struct stat st; *sdir = '\0'; /* Don't create in root directory. */ if (gOurDirectoryPath[0] != '\0') { (void) OurDirectoryPath(sdir, size, kSpoolDir); if ((stat(sdir, &st) < 0) && (MkDirs(sdir, 00700) < 0)) { perror(sdir); return (-1); } else { return (0); } } return (-1); } /* MkSpoolDir */
int GetDir(GetOptionsPtr gopt, char *dName, char *rRoot, char *lRoot) { LineList dirFiles; LinePtr dirFile; char *rd; /* Remote directory path. */ char *ld; /* Local directory path. */ char *rf; /* Complete remote pathname for an item. */ char *lf; /* Complete local pathname for an item. */ char *sl; /* What a symlink points to. */ char *iName; int fType; rd = NULL; ld = NULL; rf = NULL; lf = NULL; if ((rd = StrDup(rRoot)) == NULL) goto fail; if ((rd = PtrCatSlash(rd, dName)) == NULL) goto fail; if ((ld = StrDup(lRoot)) == NULL) goto fail; if ((ld = PtrCatSlash(ld, dName)) == NULL) goto fail; /* Create this directory on the local host first. */ if (MkDirs(ld)) { EPrintF("Could not create directory '%s.'\n", ld); goto fail; } /* Get the names of all files and subdirs. */ InitLineList(&dirFiles); GetFileList(&dirFiles, rd); /* Get all the files first. */ for (dirFile = dirFiles.first; dirFile != NULL; dirFile = dirFile->next) { fType = (int) dirFile->line[0]; if ((fType == '-') || (fType == 'l')) { iName = dirFile->line + 1; if ((rf = StrDup(rd)) == NULL) goto fail; if ((rf = PtrCatSlash(rf, iName)) == NULL) goto fail; if ((lf = StrDup(ld)) == NULL) goto fail; if ((lf = PtrCatSlash(lf, iName)) == NULL) goto fail; if (fType == '-') { gopt->rName = rf; gopt->lName = lf; DoGet(gopt); } else { #ifdef HAVE_SYMLINK sl = (char *) malloc(SZ(512)); if (sl != NULL) { if (GetSymLinkInfo(sl, SZ(512), rf) == 0) (void) symlink(sl, lf); free(sl); } #endif /* HAVE_SYMLINK */ } free(rf); free(lf); rf = NULL; lf = NULL; } if (gXferAbortFlag == SIGINT) break; /* Don't get rest of files if you interrupted. */ } /* Now get subdirectories. */ for (dirFile = dirFiles.first; dirFile != NULL; dirFile = dirFile->next) { if (gXferAbortFlag == SIGINT) break; /* Don't get rest of files if you interrupted. */ fType = (int) dirFile->line[0]; if (fType == 'd') { iName = dirFile->line + 1; if (GetDir(gopt, iName, rd, ld) < 0) break; } } free(ld); free(rd); DisposeLineListContents(&dirFiles); return (0); fail: if (rd != NULL) free(rd); if (ld != NULL) free(ld); if (rf != NULL) free(rf); if (lf != NULL) free(lf); return (-1); } /* GetDir */