Пример #1
0
static bool check_dir(acl::scan_dir& scan, const char* to, int* ncopied)
{
	const char* rpath = scan.curr_path();
	if (rpath == false)
	{
		logger_error("get from's path error: %s, to: %s",
			acl::last_serror(), to);
		return false;
	}

	SKIP(rpath);

	acl::string to_path;
	to_path << to << SEP << rpath;
	// printf(">>to_path: %s, to: %s\r\n", to_path.c_str(), to);

	if (access(to_path.c_str(), 0) == 0)
		return true;
	else
	{
		int ret = acl_make_dirs(to_path.c_str(), 0755);
		if (ret == 0)
		{
			(*ncopied)++;
			return true;
		}
		else
		{
			logger_error("make dirs(%s) error: %s",
				to_path.c_str(), acl::last_serror());
			return false;
		}
	}
}
Пример #2
0
static bool cmp_copy(acl::scan_dir& scan, const char* name,
	const acl::string& to_path, int* ncopied)
{
	const char* rpath = scan.curr_path();
	if (rpath == NULL)
	{
		logger_error("get current path error: %s, file: %s",
			acl::last_serror(), name);
		return false;
	}

	SKIP(rpath);
	SKIP(name);

//	printf(">>rpath: %s\r\n", rpath);
//	printf(">>name: %s\r\n", name);

	acl::string from_filepath;
	if (*rpath == 0)
		from_filepath << name;
	else
		from_filepath << rpath << SEP << name;

	if (strstr(from_filepath.c_str(), ".svn") != NULL
		|| strstr(from_filepath.c_str(), ".git") != NULL
		|| strstr(from_filepath.c_str(), ".cvs") != NULL
		|| strstr(from_filepath.c_str(), ".o") != NULL)
	{
		return true;
	}

	acl::ifstream from_fp;
	if (from_fp.open_read(from_filepath.c_str()) == false)
	{
		logger_error("open source file: %s error: %s",
			from_filepath.c_str(), acl::last_serror());
		return false;
	}

	acl::string to_pathbuf;
	acl::string to_filepath;
	to_pathbuf << to_path << SEP << rpath;
	to_filepath << to_path << SEP << rpath << SEP << name;

	//printf("from_filepath: %s, to_filepath: %s\r\n",
	//	from_fp.file_path(), to_filepath.c_str());

	acl::ifstream to_fp;
	if (to_fp.open_read(to_filepath.c_str()) == false)
	{
		//printf("open to file: %s error: %s\r\n", to_filepath.c_str(),
		//	acl::last_serror());
		return copy_file(from_fp, to_pathbuf, to_filepath, ncopied);
	}


	acl_int64 length;
	if ((length = to_fp.fsize()) != from_fp.fsize())
	{
		printf("to fsize: %ld, from fsize: %ld, to file: %s, "
			"from file: %s\r\n", (long) to_fp.fsize(),
			(long) from_fp.fsize(), to_filepath.c_str(),
			from_filepath.c_str());
		to_fp.close();
		return copy_file(from_fp, to_pathbuf, to_filepath, ncopied);
	}

	char from_buf[4096], to_buf[4096];
	int from_len, to_len;
	acl_int64 read_len = 0;

	while (true)
	{
		from_len = from_fp.read(from_buf, sizeof(from_buf), false);
		if (from_len == -1)
		{
			if (read_len == length)
				return true;
#ifdef WIN32
			logger_error("read from file(%s) error(%s),"
				"file size: %I64d read len: %I64d",
				from_fp.file_path(), acl::last_serror(),
				length, read_len);
#else
			logger_error("read from file(%s) error(%s),"
				"file size: %lld, read len: %lld",
				from_fp.file_path(), acl::last_serror(),
				length, read_len);
#endif

			return false;
		}

		read_len += from_len;
		to_len = to_fp.read(to_buf, from_len, true);
		if (to_len == -1)
		{
			to_fp.close();
			printf("fread from to file error: %s\r\n",
				acl::last_serror());
			return copy_file(from_fp, to_pathbuf,
					to_filepath, ncopied);
		}

		if (memcmp(from_buf, to_buf, to_len) != 0)
		{
			to_fp.close();
			logger("string not equal, from: %s, to: %s",
				from_fp.file_path(), to_filepath.c_str());
			return copy_file(from_fp, to_pathbuf,
					to_filepath, ncopied);
		}
	}
}