/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2010, Tomasz Sowa * All rights reserved. * */ #include "ln.h" #include "core/misc.h" #include "functions/functions.h" namespace Fun { Ln::Ln() { fun.url = L"ln"; } bool Ln::HasAccess() { return system->HasWriteAccess(*cur->request->dir_tab.back()); } void Ln::CreateSymbolicLink(const std::wstring & link_to) { item.Clear(); // setting the date to now item.type = Item::symlink; item.parent_id = cur->request->dir_tab.back()->id; item.url = cur->request->PostVar(L"url"); item.link_to = link_to; item.link_redirect = cur->request->IsPostVar(L"makeredirect") ? 1 : 0; item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask functions->SetUser(item); functions->PrepareUrl(item); cur->request->status = db->AddItem(item); if( cur->request->status == WINIX_ERR_OK ) log << log3 << "Ln: created a symbolic link to: " << link_to << logend; } void Ln::CreateHardLink(const std::wstring & link_to) { int res = system->FollowAllLinks(cur->request->dir_tab, link_to, dir_tab, item, false, false); if( res == 0 ) { log << log2 << "Ln: " << link_to << " is a directory (can't create a hard link)" << logend; cur->request->status = WINIX_ERR_PERMISSION_DENIED; } else if( res == 1 ) { item.SetDateToNow(); item.type = Item::file; item.parent_id = cur->request->dir_tab.back()->id; item.url = cur->request->PostVar(L"url"); item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask functions->SetUser(item); functions->PrepareUrl(item); cur->request->status = db->AddHardLink(item); if( cur->request->status == WINIX_ERR_OK ) log << log3 << "Ln: created a hard link to: " << link_to << logend; } else if( res == 5 || res == 6 ) { cur->request->status = WINIX_ERR_PERMISSION_DENIED; } else { cur->request->status = WINIX_ERR_NO_ITEM; } } // we do not use notifications for links void Ln::MakePost() { link_to = cur->request->PostVar(L"linkto"); TrimWhite(link_to); if( link_to.empty() ) return; int type = Toi(cur->request->PostVar(L"linktype")); if( type == 0 ) CreateHardLink(link_to); else CreateSymbolicLink(link_to); if( cur->request->status == WINIX_ERR_OK ) system->RedirectTo(item); } } // namespace