Example #1
0
File: dpth.c Project: Shloub/burp
static FILE *open_data_file_for_write(struct dpth *dpth, struct blk *blk)
{
	FILE *fp=NULL;
	char *path=NULL;
	char *savepathstr=NULL;
	struct dpth_lock *head=dpth->head;
//printf("moving for: %s\n", blk->save_path);

	savepathstr=bytes_to_savepathstr(blk->savepath);

	// Sanity check. They should be coming through from the client
	// in the same order in which we locked them.
	// Remember that the save_path on the lock list is shorter than the
	// full save_path on the blk.
	if(!head
	  || strncmp(head->save_path,
		//FIX THIS
		savepathstr, sizeof(head->save_path)-1))
	{
		logp("lock and block save_path mismatch: %s %s\n",
			head?head->save_path:"(null)", savepathstr);
		goto end;
	}

	if(!(path=prepend_slash(dpth->base_path, savepathstr, 14)))
		goto end;
	fp=file_open_w(path, "wb");
end:
	if(path) free(path);
	return fp;
}
Example #2
0
File: dpth.c Project: Shloub/burp
int dpth_fwrite(struct dpth *dpth, struct iobuf *iobuf, struct blk *blk)
{
	//printf("want to write: %s\n", blk->save_path);

	// Remember that the save_path on the lock list is shorter than the
	// full save_path on the blk.
	if(dpth->fp
	  && strncmp(dpth->head->save_path,
		bytes_to_savepathstr(blk->savepath),
		sizeof(dpth->head->save_path)-1)
	  && release_and_move_to_next_in_list(dpth))
		return -1;

	// Open the current list head if we have no fp.
	if(!dpth->fp
	  && !(dpth->fp=open_data_file_for_write(dpth, blk))) return -1;

	return fwrite_buf(CMD_DATA, iobuf->buf, iobuf->len, dpth->fp);
}
Example #3
0
int manio_write_sig_and_path(struct manio *manio, struct blk *blk)
{
	if(manio->hook_sort && is_hook(blk->fingerprint))
	{
		// Add to list of hooks for this manifest chunk.
		snprintf(manio->hook_sort[manio->hook_count++], WEAK_STR_LEN,
			"%016"PRIX64,
			blk->fingerprint);
	}
	if(manio->dindex_sort)
	{
		char *savepathstr=bytes_to_savepathstr(blk->savepath);
		// Ignore obvious duplicates.
		if(!manio->hook_count
		  || strncmp(manio->dindex_sort[manio->hook_count-1],
			savepathstr, MSAVE_PATH_LEN))
		{
			// Add to list of dindexes for this manifest chunk.
			snprintf(manio->dindex_sort[manio->dindex_count++],
				MSAVE_PATH_LEN+1, "%s", savepathstr);
		}
	}
	return write_sig_msg(manio, sig_to_msg(blk, 1 /* save_path */));
}