Ejemplo n.º 1
0
static void
disk_remove_file(DEVICE * dev, uint32 file_id)
{
	DISK_DEVICE_INFO * info;
	FILE_INFO * curr;
	FILE_INFO * prev;

	info = (DISK_DEVICE_INFO *) dev->info;
	for (prev = NULL, curr = info->head; curr; prev = curr, curr = curr->next)
	{
		if (curr->file_id == file_id)
		{
			LLOGLN(10, ("disk_remove_file: id=%d", curr->file_id));

			if (curr->file != -1)
				close(curr->file);
			if (curr->dir)
				closedir(curr->dir);
			if (curr->delete_pending)
			{
				if (curr->is_dir)
				{
					disk_remove_dir(curr->fullpath);
				}
				else
				{
					unlink(curr->fullpath);
				}
			}

			if (curr->fullpath)
				free(curr->fullpath);
			if (curr->pattern)
				free(curr->pattern);

			if (prev == NULL)
				info->head = curr->next;
			else
				prev->next  = curr->next;

			free(curr);
			break;
		}
	}
}
Ejemplo n.º 2
0
/*********************************************************************************
  *函数名称:int disk_remove_dir(const char* pc_path)  
  *功能描述:删除一个目录(文件夹)和文件夹内部的所有文件,该目录最长为255字节
  *输	入: pc_path :要删除的目录路径,长度限制为255字节
  *输	出: none
  *返 回 值:非0值:该目录不存在或删除失败,0:删除成功
  *---------------------------------------------------------------------------------
  * @修改人		修改时间   	修改内容
  * 白养民		2015-06-17	创建
*********************************************************************************/
int disk_remove_dir(const char* pc_path)  
{
	DIR * pt_dir;
	struct dirent * pt_dirent;
	char c_tmp_buf[256];
	int  i_ret = 0;
	
	pt_dir = opendir(pc_path);
	
	if(pt_dir != NULL)
	{
		while((pt_dirent = readdir(pt_dir)) != NULL)
		{
			if(strcmp(pt_dirent->d_name,"..") && strcmp(pt_dirent->d_name,"."))
			{
				if(4 == pt_dirent->d_type)
				{
					memset(c_tmp_buf,0,sizeof(c_tmp_buf));
					strcpy(c_tmp_buf,pc_path);
					strcat(c_tmp_buf,"/");
					strcat(c_tmp_buf,pt_dirent->d_name);
					i_ret += disk_remove_dir(c_tmp_buf);
				}
				else
				{
					remove(pt_dirent->d_name);
					printf("FIL_REMOVE:%s/%s   d_type:%d\n",pc_path, pt_dirent->d_name,pt_dirent->d_type);
				}
			}
		}
		closedir(pt_dir);
	}
	else
	{
		i_ret = 1;
	}
	rmdir(pc_path);
	printf("DIR_REMOVE:%s\n", pc_path);
	return i_ret;
}  
Ejemplo n.º 3
0
static uint32
disk_remove_dir(const char * path)
{
	DIR * dir;
	struct dirent * pdirent;
	struct stat file_stat;
	char * p;
	uint32 ret = RD_STATUS_SUCCESS;

	dir = opendir(path);
	if (dir == NULL)
		return get_error_status();

	pdirent = readdir(dir);
	while (pdirent)
	{
		if (strcmp(pdirent->d_name, ".") == 0 || strcmp(pdirent->d_name, "..") == 0)
		{
			pdirent = readdir(dir);
			continue;
		}

		p = malloc(strlen(path) + strlen(pdirent->d_name) + 2);
		sprintf(p, "%s/%s", path, pdirent->d_name);
		if (stat(p, &file_stat) != 0)
		{
			LLOGLN(0, ("disk_remove_dir: stat %s failed (%i)\n", p, errno));
			ret = get_error_status();
		}
		else if (S_ISDIR(file_stat.st_mode))
		{
			ret = disk_remove_dir(p);
		}
		else
		{
			if (unlink(p) < 0)
			{
				LLOGLN(0, ("disk_remove_dir: unlink %s failed (%i)\n", p, errno));
				ret = get_error_status();
			}
		}
		free(p);

		if (ret != RD_STATUS_SUCCESS)
			break;

		pdirent = readdir(dir);
	}

	closedir(dir);
	if (ret == RD_STATUS_SUCCESS)
	{
		if (rmdir(path) < 0)
		{
			LLOGLN(0, ("disk_remove_dir: rmdir %s failed (%i)\n", path, errno));
			ret = get_error_status();
		}
	}

	return ret;
}