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:
105
content/cp.cpp
Executable file
105
content/cp.cpp
Executable 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();
|
||||
}
|
Reference in New Issue
Block a user