Exemplo n.º 1
0
status_t TrashFile(BEntry *src)
{
	// Move a file to the Trash. If the name exists, rename the entry before moving
	
	if(!src)
		return B_ERROR;
	
	status_t status;
	BPath path;
	BEntry dest;
	BString pathstr("/boot/home/Desktop/Trash/");
	BDirectory dir(pathstr.String());
	
	char newname[B_FILE_NAME_LENGTH];
	src->GetName(newname);
	pathstr+=newname;
	
	dest.SetTo(pathstr.String());
	GetValidName(&dest);
	dest.GetPath(&path);
	
	BPath srcpath;
	src->GetPath(&srcpath);
	BNode node(srcpath.Path());
	if(node.InitCheck()==B_OK)
	{
		node.WriteAttr("_trk/original_path",B_STRING_TYPE,0,
				srcpath.Path(),strlen(srcpath.Path())+1);
	}
	
	status=src->MoveTo(&dir,path.Path(),false);
	
	if(status==B_CROSS_DEVICE_LINK)
	{
		BPath srcpath;
		src->GetPath(&srcpath);
		BString command("mv "),srcstring(srcpath.Path()),deststring(path.Path());
		srcstring.CharacterEscape(" ",'\\');
		deststring.CharacterEscape(" ",'\\');
		command+=srcstring;
		command+=" ";
		command+=deststring;
		system(command.String());
	}
	return status;

}
Exemplo n.º 2
0
status_t CopyFile(BEntry *srcentry, BEntry *destentry, bool clobber)
{
	if(!srcentry || !destentry)
		return B_ERROR;
	
	if (!destentry->IsDirectory())
		return B_ERROR;
		
	entry_ref ref;
	srcentry->GetRef(&ref);
	
	BPath srcpath;
	srcentry->GetPath(&srcpath);
	
	BString srcstring(srcpath.Path());
	srcstring.CharacterEscape("'",'\\');
	
	BPath destpath;
	destentry->GetPath(&destpath);
	
	BString deststring(destpath.Path());
	deststring.CharacterEscape("'",'\\');
	
	BString command("copyattr -r -d ");
	command << "'" << srcstring << "' '" << deststring << "/'";
	int code = system(command.String());
	
	if (!code)
	{
		entry_ref ref;
		srcentry->GetRef(&ref);
		
		deststring << "/" << ref.name;
		return srcentry->SetTo(deststring.String());
	}
		
	return code;
}