コード例 #1
0
ファイル: rdiff.c プロジェクト: Estevo-Aleixo/librsync
static rs_result rdiff_patch(poptContext opcon)
{
    /*  patch BASIS [DELTA [NEWFILE]] */
    FILE               *basis_file, *delta_file, *new_file;
    char const         *basis_name;
    rs_stats_t          stats;
    rs_result           result;

    if (!(basis_name = poptGetArg(opcon))) {
        rdiff_usage("Usage for patch: "
                    "rdiff [OPTIONS] patch BASIS [DELTA [NEW]]");
        return RS_SYNTAX_ERROR;
    }

    basis_file = rs_file_open(basis_name, "rb");
    delta_file = rs_file_open(poptGetArg(opcon), "rb");
    new_file =   rs_file_open(poptGetArg(opcon), "wb");

    rdiff_no_more_args(opcon);

    result = rs_patch_file(basis_file, delta_file, new_file, &stats);

    rs_file_close(new_file);
    rs_file_close(delta_file);
    rs_file_close(basis_file);

    if (show_stats) 
        rs_log_stats(&stats);

    return result;
}
コード例 #2
0
ファイル: rpatch.c プロジェクト: williamkun/librsync-example
int main(int argc, char *argv[])
{
	FILE *basis_file;
	FILE *delta_file;
	rs_result ret;
	FILE *new_file;
	rs_stats_t stats;

	if(argc != 4)
	{
		fprintf(stderr, "invalid argument(s)\n");
		exit(1);
	}

	basis_file = fopen(argv[1], "rb");
	delta_file = fopen(argv[2], "rb");
	new_file = fopen(argv[3], "wb");

	ret = rs_patch_file(basis_file, delta_file, new_file, &stats);
	fclose(basis_file);
	fclose(delta_file);
	fclose(new_file);
	if(ret != RS_DONE)
	{
		puts(rs_strerror(ret));
		exit(1);
	}
	rs_log_stats(&stats);
	return 0;
}
コード例 #3
0
ファイル: ffstorage.cpp プロジェクト: rayfung/ffbackup-server
bool rsync_patch(const std::string &basis_file_path, const std::string &patch_file_path,
                 const std::string &new_file_path)
{
    FILE *basis_file;
    FILE *delta_file;
    rs_result ret;
    FILE *new_file;
    rs_stats_t stats;

    basis_file = fopen(basis_file_path.c_str(), "rb");
    if(basis_file == NULL)
        return false;

    delta_file = fopen(patch_file_path.c_str(), "rb");
    if(delta_file == NULL)
    {
        fclose(basis_file);
        return false;
    }

    new_file = fopen(new_file_path.c_str(), "wb");
    if(new_file == NULL)
    {
        fclose(basis_file);
        fclose(delta_file);
        return false;
    }

    ret = rs_patch_file(basis_file, delta_file, new_file, &stats);
    fclose(basis_file);
    fclose(delta_file);
    fclose(new_file);
    return (ret == RS_DONE);
}
コード例 #4
0
ファイル: LibRsyncDll.cpp プロジェクト: fmaj7/HoneyBadger
bool rsync_patch(char* oldfile,char* newfile,char* deltafile){
	FILE* old=FileUtil::rs_file_open(oldfile,"rb");
	FILE* delta=FileUtil::rs_file_open(deltafile,"rb");
	FILE* newf=FileUtil::rs_file_open(newfile,"wb");
	rs_result rs=rs_patch_file(old,delta,newf,NULL);
	FileUtil::rs_file_close(old);
	FileUtil::rs_file_close(newf);
	FileUtil::rs_file_close(delta);
	if(rs!=RS_DONE){
		return false;}else{
		return true;}
}
コード例 #5
0
ファイル: rsync.c プロジェクト: carriercomm/csync2-2
int csync_rs_patch(const char *filename)
{
	FILE *basis_file = 0, *delta_file = 0, *new_file = 0;
	int backup_errno;
	rs_stats_t stats;
	rs_result result;
	char *errstr = "?";
	char tmpfname[MAXPATHLEN], newfname[MAXPATHLEN];

	csync_debug(3, "Csync2 / Librsync: csync_rs_patch('%s')\n", filename);

	csync_debug(3, "Receiving delta_file from peer..\n");
	delta_file = open_temp_file(tmpfname, prefixsubst(filename));
	if ( !delta_file ) { errstr="creating delta temp file"; goto io_error; }
	if (unlink(tmpfname) < 0) { errstr="removing delta temp file"; goto io_error; }
	if ( csync_recv_file(delta_file) ) goto error;

	csync_debug(3, "Opening to be patched file on local host..\n");
	basis_file = fopen(prefixsubst(filename), "rb");
	if ( !basis_file ) {
		basis_file = open_temp_file(tmpfname, prefixsubst(filename));
		if ( !basis_file ) { errstr="opening data file for reading"; goto io_error; }
		if (unlink(tmpfname) < 0) { errstr="removing data temp file"; goto io_error; }
	}

	csync_debug(3, "Opening temp file for new data on local host..\n");
	new_file = open_temp_file(newfname, prefixsubst(filename));
	if ( !new_file ) { errstr="creating new data temp file"; goto io_error; }

	csync_debug(3, "Running rs_patch_file() from librsync..\n");
	result = rs_patch_file(basis_file, delta_file, new_file, &stats);
	if (result != RS_DONE) {
		csync_debug(0, "Internal error from rsync library!\n");
		goto error;
	}

	csync_debug(3, "Renaming tmp file to data file..\n");
	fclose(basis_file);

#ifdef __CYGWIN__

/* TODO: needed? */
	// This creates the file using the native windows API, bypassing
	// the cygwin wrappers and so making sure that we do not mess up the
	// permissions..
	{
		char winfilename[MAX_PATH];
		HANDLE winfh;

		cygwin_conv_to_win32_path(prefixsubst(filename), winfilename);

		winfh = CreateFile(TEXT(winfilename),
				GENERIC_WRITE,          // open for writing
				0,                      // do not share
				NULL,                   // default security
				CREATE_ALWAYS,          // overwrite existing
				FILE_ATTRIBUTE_NORMAL | // normal file
				FILE_FLAG_OVERLAPPED,   // asynchronous I/O
				NULL);                  // no attr. template

		if (winfh == INVALID_HANDLE_VALUE) {
			csync_debug(0, "Win32 I/O Error %d in rsync-patch: %s\n",
					(int)GetLastError(), winfilename);
			errno = EACCES;
			goto error;
		}
		CloseHandle(winfh);
	}
#endif

	if (rename(newfname, prefixsubst(filename)) < 0) { errstr="renaming tmp file to to be patched file"; goto io_error; }

	csync_debug(3, "File has been patched successfully.\n");
	fclose(delta_file);
	fclose(new_file);

	return 0;

io_error:
	csync_debug(0, "I/O Error '%s' while %s in rsync-patch: %s\n",
			strerror(errno), errstr, prefixsubst(filename));

error:;
	backup_errno = errno;
	if ( delta_file ) fclose(delta_file);
	if ( basis_file ) fclose(basis_file);
	if ( new_file )   fclose(new_file);
	errno = backup_errno;
	return -1;
}