19 #include <boost/lexical_cast.hpp>
32 n = ft->eatPath(path);
39 n.get()->getProperties().get()->setRoot(json);
47 int WsFsTreeModification::saveProperty(
const std::set<std::string>& groups,
const std::string& path,
const std::string& section,
const std::string& attr,
const std::string& val)
51 n = ft->eatPath(path);
58 n.get()->getProperties().get()->set(section, attr, val);
69 boost::filesystem::path parent = p;
71 parent = parent.parent_path();
74 n = ft->eatPath(parent.string());
76 LOG(
ERROR) <<
"WsFsTreeClient::createNode() : Parent Node not found " << parent.string();
80 if ( !n.get()->isDirectory()) {
81 LOG(
ERROR) <<
"WsFsTreeClient::createNode() : Parent Node is not a directory " << parent.string();
88 if (ft->eatPath(p).get() != 0) {
89 LOG(
INFO) <<
"WsFsTreeClient::createNode() : Node already exist" << p;
96 f.open(
string(root.string() + p).c_str(), ios::out );
113 boost::filesystem::create_directory(root / path(p));
114 }
catch (std::exception& e) {
115 LOG(
ERROR) <<
"WsFsTreeClient::createNode() : could not create node " << e.what();
124 fp->setGroups(groups);
132 }
catch (std::exception& e) {
133 LOG(
ERROR) <<
"WsFsTreeClient::createNode() : could not create node " << e.what();
148 LOG(
ERROR) <<
"WsFsTreeClient::deleteNode() : Node not found " << p;
153 if ( !boost::filesystem::exists(ft->getRootPath() / p)) {
154 LOG(
ERROR) <<
"WsFsTreeClient::deleteNode() : Node do not exist" << p;
157 if ( n.get()->isRegularFile()) {
159 std::string propFileName = n.get()->getName() +
".json";
163 }
catch (std::exception& e) {
164 LOG(
ERROR) <<
"WsFsTreeClient::deleteNode() : could not delete node " << propFileName <<
" : " << e.what();
167 LOG(
INFO) <<
"WsFsTreeClient::deleteNode() : Removing config files for " << p;
169 std::string lockFileName = n.get()->getName() +
".lock";
173 }
catch (std::exception& e) {
174 LOG(
ERROR) <<
"WsFsTreeClient::deleteNode() : could not delete node " << lockFileName <<
" : " << e.what();
177 LOG(
INFO) <<
"WsFsTreeClient::deleteNode() : Removing lock files for " << p;
182 boost::filesystem::remove_all(ft->getRootPath() / p);
183 }
catch (std::exception& e) {
184 LOG(
ERROR) <<
"WsFsTreeClient::deleteNode() : could not create node " << e.what();
187 LOG(
INFO) <<
"WsFsTreeClient :: Removing Node " << p;
198 LOG(
ERROR) <<
"WsFsTreeClient::renameNode() : Node not found " << p;
202 if (!n.get()->getParent()->isDirectory()) {
203 LOG(
DEBUG) <<
"WsFsDaemon::renameNode() : Rename dest parent not a dir";
208 if ( !boost::filesystem::exists(root / p)) {
209 LOG(
ERROR) <<
"WsFsTreeClient::renameNode() : Node do not exist" << p;
213 if ( !boost::filesystem::exists(root / path(newPath).parent_path())) {
214 LOG(
ERROR) <<
"WsFsTreeClient::renameNode() : Parent dest node do not exist" << p;
218 if ( boost::filesystem::exists(root / newPath)) {
219 LOG(
ERROR) <<
"WsFsTreeClient::renameNode() : Destination already exist" << newPath;
222 if (n.get()->isRegularFile() ) {
228 if (exists(oldConfPath / oldConfFilename)) {
231 rename(oldConfPath / oldConfFilename , newConfPath / newConfFilename);
232 }
catch (std::exception& e) {
233 LOG(
ERROR) <<
"WsFsTreeClient::renameNode() : could not create node " << e.what();
240 boost::filesystem::rename(ft->getRootPath() / p, ft->getRootPath() / newPath );
241 if (n->isDirectory()) {
262 }
catch (std::exception& e) {
263 LOG(
ERROR) <<
"WsFsTreeClient::renameNode() : could not create node " << e.what();
271 return groups.count(
m_conf->
get(
"global",
"editor_group",
"editor")) > 0;
276 return groups.count(
m_conf->
get(
"global",
"admin_group",
"administrator")) > 0;
282 if ((node.get()->isAllowed(groups) && groups.count(
m_conf->
get(
"global",
"editor_group",
"editor")) > 0)
283 || groups.count(
m_conf->
get(
"global",
"admin_group",
"administrator")) > 0){
284 LOG(
DEBUG)<<
"WsFsTreeModification::canEdit() : user can edit ";
287 LOG(
DEBUG)<<
"WsFsTreeModification::canEdit() : user cannot edit ";
int renameNode(const std::set< std::string > &groups, const std::string &uid, const string &path, const string &newPath)
renames a node
const std::string PathToConfig
WsFsTreeModification(WsFsTreeUpdater *updater)
Constructor.
boost::shared_ptr< WsAbstractNode > NodePtr
int saveProperty(const std::set< std::string > &groups, const std::string &path, const std::string §ion, const std::string &attr, const std::string &val)
save a property of the node. The user must have access and edit rights for the node.
Reprensents a Directory on disk.
int createNode(const std::set< std::string > &groups, const std::string &uid, const string &path, int type)
create a directory or File. If the node is a WsDirNode than it will be only accessible to the Admin a...
Reprensents a File on disk.
handles the update of the FileSystemTree
const std::string PathToNodeProperties
FileSystemTreePtr getLastTree()
returns the last created tree
void setProperties(NodePropertiesPtr properties)
set the properties of the node. The properties are a WsAbstractProperties object. ...
WsFsTreeUpdater * m_updater
WsGlobalProperties * m_conf
int deleteNode(const std::set< std::string > &groups, const std::string &uid, const string &path)
delete a node. The user must be an Admin on editor to remove the node
boost::shared_ptr< WsFileSystemTree > FileSystemTreePtr
std::string get(const std::string §ion, const std::string &id, const std::string &def)
const std::string PathToNodeLock
bool isEditor(const std::set< std::string > &groups)
bool isAdministrator(const std::set< std::string > &groups)
boost::shared_ptr< WsNodeProperties > NodePropertiesPtr
static WsGlobalProperties * instance()
int saveProperties(const std::set< std::string > &groups, const std::string &json, const std::string &path)
save the properties of the node. The user must have access and edit rights for the node...
const std::string ConfExt
bool canEdit(NodePtr node, std::set< std::string > groups)
return true if the user can edit false otherwise