예제 #1
0
파일: save.c 프로젝트: jdolan/q2pro
static int wipe_save_dir(const char *dir)
{
    void **list;
    int i, count, ret = 0;

    if ((list = list_save_dir(dir, &count)) == NULL)
        return 0;

    for (i = 0; i < count; i++)
        ret |= remove_file(dir, list[i]);

    FS_FreeList(list);
    return ret;
}
예제 #2
0
파일: commands.c 프로젝트: kurt-vd/sxiv
bool it_reload_image(arg_t a) {
	if (mode == MODE_IMAGE) {
		load_image(fileidx);
	} else {
		win_set_cursor(&win, CURSOR_WATCH);
		if (!tns_load(&tns, tns.sel, &files[tns.sel], true, false)) {
			remove_file(tns.sel, false);
			tns.dirty = true;
			if (tns.sel >= tns.cnt)
				tns.sel = tns.cnt - 1;
		}
	}
	return true;
}
/**
 * @brief 执行rm命令 
 * @details 删除指定文件
 * @param[in] remove_paths 需要删除的文件的路径
 * @param[in] recursive    是否递归删除
 * @param[in] force        是否强行删除只读文件
 * @return 成功返回true,失败返回false
 */
bool rm( const char * const * const remove_paths, bool recursive, bool force )
{
	char absolute_path[MAX_PATH];
	const char * const * p = NULL;

	assert(remove_paths != NULL);
	for ( p = remove_paths; (*p) != NULL; ++ p )
	{
		get_absolute_path(absolute_path, *p);
		if ( !remove_file(absolute_path) )
			fprintf(stderr, "rm: cannot remove ‘%s’: No such file or directory\n", (*p));
	}
	return true;
}
예제 #4
0
void remove_files() {
	remove_file(DATA_IN, 1);
	remove_file(DATA_OUT, 1);
	remove_file(RE_OUT, 1);
	remove_file(CE_OUT, 1);
	remove_file(USER_CODE, 1);
	remove_file(COMPILED_FILE, 1);
	return;
}
예제 #5
0
void init_remove_files() {
	remove_file(DATA_IN, 0);
	remove_file(DATA_OUT, 0);
	remove_file(RE_OUT, 0);
	remove_file(CE_OUT, 0);
	remove_file(USER_CODE, 0);
	remove_file(COMPILED_FILE, 0);
	return;
}
예제 #6
0
파일: man.c 프로젝트: haggaie/man
static void
remove_other_catfiles (const char *catfile) {
     char *pathname;
     char *t;
     char **gf;
     int offset;

     pathname = my_strdup(catfile);
     t = rindex(pathname, '.');
     if (t == NULL || strcmp(t, getval("COMPRESS_EXT")))
	  return;
     offset = t - pathname;
     strcpy(t, "*");
     gf = glob_filename (pathname);

     if (gf != (char **) -1 && gf != NULL) {
	  for ( ; *gf; gf++) {
	       /*
		* Only remove files with a known extension, like .Z
		* (otherwise we might kill a lot when called with
		* catfile = ".gz" ...)
		*/
	       if (strlen (*gf) <= offset) {
		    if (strlen (*gf) == offset)  /* uncompressed version */
			 remove_file (*gf);
		    continue;
	       }

	       if (!strcmp (*gf + offset, getval("COMPRESS_EXT")))
		    continue;

	       if (get_expander (*gf) != NULL)
		    remove_file (*gf);
	  }
     }
}
예제 #7
0
파일: qib_fs.c 프로젝트: 01org/qib
static int remove_device_files(struct super_block *sb,
			       struct qib_devdata *dd)
{
	struct dentry *dir, *root;
	char unit[10];
	int ret, i;

	root = dget(sb->s_root);
	mutex_lock(&root->d_inode->i_mutex);
	snprintf(unit, sizeof unit, "%u", dd->unit);
	dir = lookup_one_len(unit, root, strlen(unit));

	if (IS_ERR(dir)) {
		ret = PTR_ERR(dir);
		printk(KERN_ERR "Lookup of %s failed\n", unit);
		goto bail;
	}

	remove_file(dir, "counters");
	remove_file(dir, "counter_names");
	remove_file(dir, "portcounter_names");
	for (i = 0; i < dd->num_pports; i++) {
		char portcntr[24];

		sprintf(portcntr, "port%dcounters", i + 1);
		remove_file(dir, portcntr);
	}
	remove_file(dir, "flash");
	d_delete(dir);
	ret = simple_rmdir(root->d_inode, dir);

bail:
	mutex_unlock(&root->d_inode->i_mutex);
	dput(root);
	return ret;
}
예제 #8
0
ErrnoError remove_directory(const std::string& path, bool is_recursive) {
  if (path.empty()) {
    return make_error_perror("remove_directory", EINVAL);
  }

  std::string pr_path = prepare_path(path);
  if (pr_path[pr_path.length() - 1] == get_separator<char>()) {
    pr_path[pr_path.length() - 1] = 0;
  }

  const char* pr_path_ptr = pr_path.c_str();
  if (is_recursive) {
    DIR* dirp = opendir(pr_path_ptr);
    if (!dirp) {
      return ErrnoError();
    }

    struct dirent* p;
    while ((p = readdir(dirp)) != nullptr) {
      /* Skip the names "." and ".." as we don't want to recurse on them. */
      if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) {
        continue;
      }

      char pathBuffer[PATH_MAX] = {0};
      SNPrintf(pathBuffer, sizeof(pathBuffer), "%s/%s", path, p->d_name);
      struct stat statbuf;
      if (!::stat(pathBuffer, &statbuf)) {
        if (S_ISDIR(statbuf.st_mode)) {
          ErrnoError err = remove_directory(pathBuffer, is_recursive);
          if (err) {
            closedir(dirp);
            return err;
          }
        } else {
          ErrnoError err = remove_file(pathBuffer);
          if (err) {
            closedir(dirp);
            return err;
          }
        }
      }
    }
    closedir(dirp);
  }

  return do_rmdir_directory(pr_path_ptr);
}
예제 #9
0
void fileaction_dobackup(char *filename, int fileref)
{
    struct stat oldfile;
    int stat_res;
    char *newname;
    if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */
        stat_res = lstat (filename, &oldfile);
        if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists  - really should check MD5's etc to see if different */
            newname = bb_xstrdup(filename);
            newname = strcat(newname, ".rpmorig");
            copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
            remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
            free(newname);
        }
    }
}
예제 #10
0
static void conflict_rename_rename_2(struct rename *ren1,
				     const char *branch1,
				     struct rename *ren2,
				     const char *branch2)
{
	char *new_path1 = unique_path(ren1->pair->two->path, branch1);
	char *new_path2 = unique_path(ren2->pair->two->path, branch2);
	output(1, "Renamed %s to %s and %s to %s instead",
	       ren1->pair->one->path, new_path1,
	       ren2->pair->one->path, new_path2);
	remove_file(0, ren1->pair->two->path, 0);
	update_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path1);
	update_file(0, ren2->pair->two->sha1, ren2->pair->two->mode, new_path2);
	free(new_path2);
	free(new_path1);
}
예제 #11
0
void FilesystemTest::testFile() {
#ifdef _WIN32
	const string test_file = test_dir->Path() + "\\test-file.txt";
#else
	const string test_file = test_dir->Path() + "/test-file";
#endif

	CPPUNIT_ASSERT_MESSAGE(
		"inexistant file is file",
		!is_file(test_file));
	CPPUNIT_ASSERT_EQUAL_MESSAGE(
		"mtime of inexistant file should be zero",
		time_t(0), file_mtime(test_file));
	CPPUNIT_ASSERT_MESSAGE(
		"inexistant file is a directory",
		!is_dir(test_file));

	{ // create file
		ofstream file(test_file);
		file << "hello" << endl;
	}
	time_t now = time(nullptr);
	CPPUNIT_ASSERT_MESSAGE(
		"existing file not a file",
		is_file(test_file));
	CPPUNIT_ASSERT_MESSAGE(
		"mtime of existing file should be somewhere around now",
		// let's assume that creating the file takes less than five seconds
		abs(now - file_mtime(test_file) < 5));
	CPPUNIT_ASSERT_MESSAGE(
		"regular file is a directory",
		!is_dir(test_file));

	CPPUNIT_ASSERT_MESSAGE(
		"failed to remove test file",
		remove_file(test_file));

	CPPUNIT_ASSERT_MESSAGE(
		"removed file is still a file",
		!is_file(test_file));
	CPPUNIT_ASSERT_EQUAL_MESSAGE(
		"mtime of removed file should be zero",
		time_t(0), file_mtime(test_file));
	CPPUNIT_ASSERT_MESSAGE(
		"removed file became a directory",
		!is_dir(test_file));
}
예제 #12
0
파일: cu_list.c 프로젝트: bnordgren/postgis
void test_remove_middle(void)
{
	FILENODE *node[5];
	FILENODE *current_node;
	GtkTreeIter iter;
	int i = 0;
	init_file_list();

	node[0] = append_file("file1", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[0]);
	node[1] = append_file("file2", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[1]);
	node[2] = append_file("file3", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[2]);
	node[3] = append_file("file4", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[3]);
	node[4] = append_file("file5", "schema", "table", "geom_column", "-1", 'c', &iter);
	CU_ASSERT_PTR_NOT_NULL(node[4]);

	current_node = get_next_node(NULL);
	CU_ASSERT_PTR_NOT_NULL(current_node);
	while (current_node != NULL)
	{
		CU_ASSERT_NOT_EQUAL(i, 5);
		CU_ASSERT_PTR_EQUAL(current_node, node[i]);
		current_node = get_next_node(current_node);
		i++;
	}

	remove_file(node[3]);
	i = 0;
	current_node = get_next_node(NULL);
	CU_ASSERT_PTR_NOT_NULL(current_node);
	while (current_node != NULL)
	{
		CU_ASSERT_NOT_EQUAL(i, 5);
		CU_ASSERT_PTR_EQUAL(current_node, node[i]);
		current_node = get_next_node(current_node);
		i++;
		if (i == 3)
			i++;
	}
	CU_ASSERT_EQUAL(i, 5);

	destroy_file_list();

}
예제 #13
0
파일: commands.c 프로젝트: hirkmt/sxiv
bool it_shell_cmd(arg_t a)
{
    int n, status;
    const char *cmdline = (const char*) a;
    pid_t pid;

    if (cmdline == NULL || *cmdline == '\0')
        return false;

    n = mode == MODE_IMAGE ? fileidx : tns.sel;

    if (setenv("SXIV_IMG", files[n].path, 1) < 0) {
        warn("could not set env.-variable: SXIV_IMG. command line was: %s",
             cmdline);
        return false;
    }

    if ((pid = fork()) == 0) {
        execl("/bin/sh", "/bin/sh", "-c", cmdline, NULL);
        warn("could not exec: /bin/sh. command line was: %s", cmdline);
        exit(EXIT_FAILURE);
    } else if (pid < 0) {
        warn("could not fork. command line was: %s", cmdline);
        return false;
    }

    win_set_cursor(&win, CURSOR_WATCH);

    waitpid(pid, &status, 0);
    if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0)
        warn("child exited with non-zero return value: %d. command line was: %s",
             WEXITSTATUS(status), cmdline);

    if (mode == MODE_IMAGE) {
        img_close(&img, true);
        load_image(fileidx);
    }
    if (!tns_load(&tns, n, &files[n], true, mode == MODE_IMAGE) &&
            mode == MODE_THUMB)
    {
        remove_file(tns.sel, false);
        tns.dirty = true;
        if (tns.sel >= tns.cnt)
            tns.sel = tns.cnt - 1;
    }
    return true;
}
예제 #14
0
int main(int argc, char* argv[]){
	int i=0;
	uint8_t* rd;
    uint8_t buf[30]="adfasdfasgfaaaaaaaaaaa";
    
	char name[14];
	char search_name[14];
	rd=ramdisk_init();
	int root_block_id=search_file(rd, "/");
    int search_file_inodeNO;
    int remove_flag;
    int a;
	printf("root block id is %d\n", root_block_id);
	
	struct inode* root_inode;
	if(!(root_inode=(struct inode*)malloc(sizeof(struct inode)))){
		printf("No mem space!\n");
		exit(-1);
	}
    //create_dir(rd,0,"ts_dir");
	//create a file under root named Jiayi.txt
    create_file(rd, 0, "ts_file.txt");
    for (i = 0; i<1024 ; i++)
    {
        a = write_ramdisk(rd,1,i*20,buf,20);
	    printf("a = %d; i = %d\n", a, i);
//        sprintf(name, "ts_%d.txt", i);
//        create_file(rd, 1, name);
    }

 /*   for (i = 1; i<=FILE_NUM ; i++)
    {
        sprintf(search_name, "/ts_%d.txt", i);
	    search_file_inodeNO = search_file(rd,search_name);
        printf("File InodeNO is:%d\n", search_file_inodeNO);
    }*/
    //remove_flag=remove_file(rd,0,2,"ts_2.txt");
    //(remove_flag==(-1))?(printf("Remove fail!\n")):(printf("Remove success!\n"));
    //search_file_inodeNO=search_file(rd,"/ts_2.txt");
    //printf("File InodeNO is:%d\n", search_file_inodeNO);
    remove_flag=remove_file(rd,0,1,"ts_file.txt");
    (remove_flag==(-1))?(printf("Remove fail!\n")):(printf("Remove success!\n"));
    search_file_inodeNO=search_file(rd,"/ts_file.txt");
    printf("File InodeNO is:%d\n", search_file_inodeNO);
    
	return 0;
}
예제 #15
0
void mod_manager::save_mods_list(WORLDPTR world) const
{
    if( world == NULL ) {
        return;
    }
    const std::string path = get_mods_list_file(world);
    if( world->active_mod_order.empty() ) {
        // If we were called from load_mods_list to prune the list,
        // and it's empty now, delete the file.
        remove_file(path);
        return;
    }
    write_to_file( path, [&]( std::ostream &fout ) {
        JsonOut json( fout, true ); // pretty-print
        json.write(world->active_mod_order);
    }, _( "list of mods" ) );
}
예제 #16
0
/* close a compressed mailbox */
void mutt_fast_close_compressed (CONTEXT * ctx)
{
    debug_print (2, ("called on '%s'\n", ctx->path));

    if (ctx->compressinfo) {
        if (ctx->fp)
            fclose (ctx->fp);
        ctx->fp = NULL;
        /* if the folder was removed, remove the gzipped folder too */
        if (access (ctx->path, F_OK) != 0 && !option (OPTSAVEEMPTY))
            remove (ctx->realpath);
        else
            remove_file (ctx);

        restore_path (ctx);
        mem_free (&ctx->compressinfo);
    }
}
예제 #17
0
파일: tagfs.c 프로젝트: williamwoelke/TagFS
/*
 * Remove a file.
 */
int tagfs_unlink(const char *path) {
	int retstat = 0;
	int file_id = 0;

	DEBUG(ENTRY);
	INFO("Deleting %s", path);

	file_id = file_id_from_path(path);

	if(strcmp(dirname(path), "/") == 0) {
		remove_file(file_id);
	} else {
		remove_tags(file_id);
	}

	DEBUG(EXIT);
	return retstat;
}
예제 #18
0
파일: update.cpp 프로젝트: amireh/Karazeh
  void update_operation::rollback() {
    auto file_manager = config_.file_manager;
    auto hasher       = config_.hasher;

    // did we patch the file? keep in mind that if we did:
    //
    // - patched_path_ would point to the **original** file
    // - basis_path_ would point to the **patched** file
    //
    // to avoid confusion, we'll gonna rename the references to "original" and
    // "patched":
    const path_t    &original_path(patched_path_);
    const string_t  &original_checksum(basis_checksum);
    const path_t    &modified_path(basis_path_);
    const string_t  &modified_checksum(patched_checksum);

    if (!file_manager->is_readable(modified_path)) {
      return (void)STAGE_INVALID_STATE;
    }

    auto checksum = hasher->hex_digest(modified_path);

    if (checksum == modified_checksum) {
      // make sure the original still exists
      if (!file_manager->exists(original_path)) {
        error() << "Basis no longer exists in cache, can not rollback!";

        return (void)STAGE_INVALID_STATE;
      }
      else if (hasher->hex_digest(original_path) != original_checksum) {
        error() << "Basis file seems to have changed, can not rollback!";

        return (void)STAGE_INVALID_STATE;
      }

      // remove the modified file:
      file_manager->remove_file(modified_path);

      // and move the original file back in its place:
      file_manager->move(original_path, modified_path);
    }
  }
예제 #19
0
파일: fs.cpp 프로젝트: xubingyue/mini-lake
	void remove_directories(const std::string & dir)
	{
		std::stack<std::string> directories;

		directories.push(dir);

		while(!directories.empty())
		{
			std::string	current = directories.top();

			if(is_empty(current))
			{
				remove_directory(current);

				directories.pop();

				continue;
			}

			directory_iterator_t iter(current),end;

			for(;iter != end; ++ iter)
			{
				if("." == *iter) continue;

				if(".." == *iter) continue;

				std::string path = current + "/" + *iter;

				if(is_directory(path))
				{
					if(is_empty(path)) remove_directory(path);

					else directories.push(path);
				}
				else
				{
					remove_file(path);
				}
			}
		}
	}
예제 #20
0
int remove_block(int number)
{
    int result = 0;
    int status = get_block_status(number);
    switch (status)
    {
    case BLOCK_STATUS_FREE:
        break;
    case BLOCK_STATUS_FOLDER:
        remove_folder(number);
        break;
    case BLOCK_STATUS_FILE:
        remove_file(number);
        break;
    default:
        result = -1;
        break;
    }
    return result;
}
예제 #21
0
파일: jymain.c 프로젝트: langresser/sdljy
// 主程序
int SDL_main(int argc, char *argv[])
{
	remove_file(DEBUG_FILE);
    freopen_file(ERROR_FILE,"wt",stderr);    //设置stderr输出到文件

	//初始化lua
	g_pL_main=lua_open();
    luaL_openlibs(g_pL_main);

    Lua_Config(g_pL_main,CONFIG_FILE);        //读取lua配置文件,设置参数

    InitSDL();           //初始化SDL

	InitGame();          //初始化游戏数据

#ifdef WIN32
	SDL_mainLoop();
#endif
    return 0;
}
예제 #22
0
file_cache::file_cache(int refresh_time) {
    m_thread = std::thread([this, refresh_time] {
        while (!m_stop) {
            // relax
            std::this_thread::sleep_for(std::chrono::seconds(refresh_time));
            // look for new objects
            std::unordered_set<std::string> dirs;
            {
                std::lock_guard<std::mutex> lock(m_dir_mtx);
                dirs = m_directories;
            }
            for (auto& dir : dirs) {
                scan_directory(dir);
            }
            // update/remove existing objects
            std::vector<std::string> to_remove;
            std::vector<std::string> to_add;
            {
                std::lock_guard<std::mutex> lock(m_file_mtx);
                for (auto& pair : m_file_map) {
                    path p(pair.first);
                    if (exists(p)) {
                        if (*pair.second != file(pair.first)) {
                            // changed file
                            to_add.push_back(pair.first);
                        }
                    } else {
                        // file does not exists, remove it
                        to_remove.push_back(pair.first);
                    }
                }
            }
            for (auto& f : to_add) {
                add_file(f);
            }
            for (auto& f : to_remove) {
                remove_file(f);
            }
        }
    });
}
예제 #23
0
파일: main.c 프로젝트: willtd/CitizenWater
int main(int argc, char * argv[]) {
    int sockfd = -1;
    controller_options_t opts;

    // Parse and apply command line options
    parse_options(argc, argv, &opts);
    print_options(&opts);

    DEBUG("main(): Finished parsing options...\n");

    set_log_level(opts.log_level);
    enable_syslog("citwater-controller", 1);

    // Remove any previous instance. Removing arbitrary file is a bit dangerous
    remove_file(opts.socket_file);
    sockfd = init_server(opts.socket_file);

    if (sockfd == -1)
    {
	    PERROR("main() -- init_server()");
	    exit(1);
    }

    if (daemon(0, 0) == -1)
    {
        PERROR("main() -- daemon()"); 
        exit(1);
    }

    if (atlsci_init() < 0)
    {
        ERROR("main() -- atlsci_init()");
        exit(1);
    }

    main_loop(sockfd);

    atlsci_deinit();
    disable_syslog();
    return 0;
}
/*
* builtin_cmd
*
* 내장 명령을 수행한다.
* 내장 명령이 아니면 1을 리턴한다.
*/
int builtin_cmd(int argc, char **argv)
{ 
	// 내장 명령어 문자열과 argv[0]을 비교하여 각각의 처리 함수 호출
	if ( (!strcmp (argv[0], "quit")) || (!strcmp (argv[0], "exit")) ) {
		exit(0);
	}
    if ( !strcmp(argv[0], "ls")){
       return list_files(argc, argv);
    }
    if ( !strcmp(argv[0], "ll")){
       return list_all_files(argc, argv);
    }
    if ( !strcmp(argv[0], "cp")){
        return copy_file(argc, argv);
    }
    if ( !strcmp(argv[0], "rm")){
        return remove_file(argc, argv);
    }
    if ( !strcmp(argv[0], "move")){
        return move_file(argc, argv);
    }
    if ( !strcmp(argv[0], "cd")){
        return change_directory(argc, argv);
    }
    if ( !strcmp(argv[0], "pwd")){
        return print_working_directory();
    }
    if ( !strcmp(argv[0], "mkdir")){
        return make_directory(argc, argv);
    }
    if ( !strcmp(argv[0], "rmdir")){
        return remove_directory(argc, argv);
    }
    if ( !strcmp(argv[0], "cpdir")){
        return copy_directory(argc, argv);
    }
        
	// 내장 명령어가 아님.
    printf("command not found\n");
	return 1;
}
예제 #25
0
// remove file include directory.
int remove_file(const QString &path)
{
  QDir dir(path);
  //dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::AllDirs);
  //dir.setFilter(QDir::AllDirs | QDir::Hidden);
  dir.setFilter(QDir::AllEntries);

  QFileInfoList file_info_list = dir.entryInfoList();
  qDebug("file_info_list.size() : %d", file_info_list.size());
  for (int i = 0; i < file_info_list.size(); ++i) 
  {
    QFileInfo file_info = file_info_list.at(i);
#ifdef DIR_NAME_DEG
    qDebug("file_info.fileName() : %s", file_info.fileName().toAscii().data()  );
    qDebug("file_info.isDir() : %d", file_info.isDir() );
#endif
    if (file_info.isDir() )
    {
      if ( file_info.fileName() =="." ||  file_info.fileName()=="..")
      {
        continue;
      }
      else
      {
        remove_file( path + QDir::separator() + file_info.fileName()); 
      }
      dir.rmdir( path + QDir::separator() + file_info.fileName()); 
    
    }
    else
    {
      qDebug("file_info.fileName(): %s", file_info.fileName().toAscii().data() );
      dir.remove(file_info.fileName() );    
    }
  }

  return 0;
  //qdir.rmpath(path);

}
예제 #26
0
static gboolean
have_access_to_dir(const gchar * dir, gchar ** err_string)
{
    struct stat buf;
    int result;

    if (strlen(dir) == 0)
        dir = ".";

    result = stat (dir, &buf);

    if (result == -1)
    {
        *err_string = (gchar *) g_malloc (sizeof(gchar) * 512);
        snprintf(*err_string, 512, "%s: %s", dir, strerror(errno));
        return FALSE;
    }
    else
    {
        /* Try opening a file in that dir */
        FILE * tmp;
        gchar fname [4096];
        sprintf(fname, "%s/tmp00%li", dir, time(NULL));
        tmp = fopen(fname, "w");
        if (!tmp)
        {
            *err_string = (gchar *) g_malloc (sizeof(gchar) * 512);
            if (strcmp(dir, ".") == 0 && errno == EACCES)
                strcpy(*err_string, "Cannot write to output directory!");
            else
                snprintf(*err_string, 512, "%s: %s", dir, strerror(errno));

            return FALSE;
        }
        fclose(tmp);
        remove_file(fname);
    }

    return TRUE;
}
예제 #27
0
파일: transfer.c 프로젝트: GNOME/gftp
static void
do_check_done_process (pid_t pid, int ret)
{
  gftp_viewedit_data * ve_proc;
  GList * curdata, *deldata;
  int ok;

  curdata = viewedit_processes;
  while (curdata != NULL)
    {
      ve_proc = curdata->data;
      if (ve_proc->pid != pid)
        continue;

      deldata = curdata;
      curdata = curdata->next;

      viewedit_processes = g_list_remove_link (viewedit_processes, 
                                               deldata);

      ok = _check_viewedit_process_status (ve_proc, ret);
      if (!ve_proc->view && ve_proc->dontupload)
        gftpui_refresh (ve_proc->fromwdata, 1);

      if (ok && !ve_proc->view && !ve_proc->dontupload)
	{
	  /* We were editing the file. Upload it */
          if (_prompt_to_upload_edited_file (ve_proc))
            break; /* Don't free the ve_proc structure */
        }
      else if (ve_proc->view && ve_proc->rm)
        {
	  /* After viewing the file delete the tmp file */
	  remove_file (ve_proc);
	}

      free_edit_data (ve_proc);
      break;
    }
}
예제 #28
0
bool remove_tree(const QString &path)
{
    if (!QFileInfo(path).exists())
        return true;

    stack<QString> s;
    s.push(path);
    while (!s.empty())
    {
        const QString p = s.top();
        s.pop();

        if (!QFileInfo(p).isDir())
        {
            if (!remove_file(path))
                return false;
            continue;
        }

#if QT_VERSION < 0x050000
        if (nut::OS::removetree(p.toAscii().data()))
            continue;
#else
        if (QDir(p).removeRecursively()) // 如果目录中文件在windows下有只读,会调用失败
            continue;
#endif

        QStringList children = QDir(p).entryList(QDir::Files | QDir::Dirs |
            QDir::AccessMask | QDir::NoDotAndDotDot);
        if (children.isEmpty())
            return false;
        s.push(p); // 留待下次删除
        for (size_t i = 0, sz = children.size(); i < sz; ++i)
            s.push(QFileInfo(p, children.at(i)).filePath());
    }
    return true;
}
예제 #29
0
void make_bedGraph(RefGenome *g, TYPE_WIGARRAY *array, char *outputfile, char *prefix, int binsize, int binnum, int chr, int showzero){
  int i,e;
  if(chr==1) remove_file(outputfile);
  FILE *OUT = my_fopen(outputfile, FILE_MODE_A);
  for(i=0; i<binnum; i++){
    if(i==binnum -1) e = g->chr[chr].len-1; else e = (i+1)*binsize;
    if(showzero || array[i]) fprintf(OUT, "%s %d %d %.3f\n", g->chr[chr].name, i*binsize, e, WIGARRAY2VALUE(array[i]));
  }
  fclose(OUT);

  if(chr == g->chrnum-1){
      char *command = alloc_str_new(outputfile, strlen(outputfile) + 1024);
      sprintf(command, "sort -k1,1 -k2,2n %s > %s.sort", outputfile, outputfile);
      LOG("%s\n", command);
      my_system(command);
      char *tempfile = alloc_str_new(outputfile, 1024);
      sprintf(tempfile, "%s.temp", outputfile);
      OUT = my_fopen(tempfile, FILE_MODE_A);
      fprintf(OUT, "browser position %s:%ld-%ld\n", g->chr[1].name, g->chr[1].len/3, min(g->chr[1].len/3+1000000, g->chr[1].len-1));
      fprintf(OUT, "browser hide all\n");
      fprintf(OUT, "browser pack refGene encodeRegions\n");
      fprintf(OUT, "browser full altGraph\n");
      fprintf(OUT, "track type=bedGraph name=\"%s\" description=\"Merged tag counts for every %d bp\" visibility=full\n", prefix, binsize);
      fclose(OUT);
      sprintf(command, "cat %s %s.sort > %s", tempfile, outputfile, outputfile);
      LOG("%s\n", command);
      my_system(command);
      sprintf(command, "rm %s.sort %s", outputfile, tempfile);
      LOG("%s\n", command);
      my_system(command);

      MYFREE(command);
      MYFREE(tempfile);
  }
  return;
}
예제 #30
0
int
main (int argc, char *argv[])
{
  if (argc < 3)
    {
      usage ();
      exit (0);
    }

  check_dumpdir_existance ();

  /* could also call do_fuzz, begin_fuzz is just a wrapper to
   ** pass files to do_fuzz so you don't have to specify them 
   ** manually 
   */

  if (argc == 3)
    begin_fuzz (argv[2], atoi (argv[1]), 0, 0);
  else
    begin_fuzz (argv[2], atoi (argv[1]), argc, argv);

  remove_file ();
  return 0;
}