Esempio n. 1
0
int CacheBase::Truncate(std::string path, off_t offset)
{
	pf_log[W_DEBUG] << "Truncating \"" << path << "\" at " << offset;

	pf_stat stat = GetAttr(path);
	stat.size = (size_t)offset;
	stat.ctime = time(NULL);
	stat.mtime = stat.ctime;
	stat.meta_mtime = stat.ctime;

	IDList idlist;
	idlist.insert(environment.my_id.Get());

	SetAttr(path, stat, idlist);

	FileContent& file = content_list.GetFile(path);
	file.Truncate(offset);

	return 0;
}
Esempio n. 2
0
void CacheBase::Write(std::string path, const char* buf, size_t size, off_t off)
{
	FileContent& file = content_list.GetFile(path);
	FileChunk chunk(buf, off, size);
	file.SetChunk(chunk);

	/* No need to lock cache, we don't touch its members */
	pf_stat stat = GetAttr(path);
	time_t now = time(NULL);
	stat.meta_mtime = now;
	stat.mtime = now;
	stat.ctime = now;
	IDList idlist;
	idlist.insert(environment.my_id.Get());
	if(off + (off_t)size > (off_t)stat.size)
	{
		stat.size = (size_t)off + size;
		SetAttr(path, stat, idlist);
	}

	//content_list.RefreshPeersRef(path);
}