added: function cp (only for files)

git-svn-id: svn://ttmath.org/publicrep/winix/trunk@605 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-06-03 17:38:18 +00:00
parent fe8774953a
commit 2a26968c6c
21 changed files with 377 additions and 171 deletions

105
content/cp.cpp Executable file
View File

@@ -0,0 +1,105 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <errno.h>
#include "content.h"
#include "../core/request.h"
#include "../core/data.h"
#include "../core/misc.h"
bool Content::CpCheckAccessFrom()
{
if( request.is_item )
{
if( !request.HasReadAccess(request.item) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return false;
}
}
// dirs are checked in function parser
return true;
}
void Content::CpAuth(Item & item)
{
if( !request.MakePath(item, mv_new_path, true) )
{
request.status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( CopyFile(item.auth_path, mv_new_path) )
{
log << log1 << "Content: copied static file from: " << item.auth_path << ", to: " << mv_new_path << logend;
item.auth_path = mv_new_path;
request.status = db.EditAuthById(item, item.id);
}
else
{
log << log1 << "Content: can't copy a file from: " << item.auth_path << ", to: " << mv_new_path << logend;
request.status = WINIX_ERR_PERMISSION_DENIED;
}
}
void Content::CpItem(Item & item, bool redirect)
{
if( MoveIsTheSameFile(item) )
return;
if( !mv_file.empty() )
{
item.url = mv_file;
PrepareUrl(item);
}
item.parent_id = mv_dir_id;
PostFunEmacsAdd(item);
if( request.status == WINIX_ERR_OK )
{
if( item.auth != Item::auth_none )
CpAuth(item);
if( redirect )
RedirectTo(item);
}
}
void Content::PostFunCp()
{
if( CpCheckAccessFrom() &&
MoveParseDir(mv_dir_id, mv_dir, mv_file) &&
MoveCheckAccessTo(mv_dir_id) )
{
if( request.is_item )
{
CpItem(request.item);
}
else
{
/* not implemented yet */
request.status = WINIX_ERR_PERMISSION_DENIED;
}
}
}
void Content::FunCp()
{
CpCheckAccessFrom();
}