2011-08-26 01:53:49 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-01-12 03:24:08 +01:00
|
|
|
* Copyright (c) 2011-2012, Tomasz Sowa
|
2011-08-26 01:53:49 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "groupinfo.h"
|
|
|
|
#include "core/log.h"
|
|
|
|
#include "core/system.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace GroupItem
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
GroupInfo::GroupInfo()
|
|
|
|
{
|
|
|
|
mount_par_group_conf = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GroupInfo::SetSystem(System * psystem)
|
|
|
|
{
|
|
|
|
system = psystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-16 23:33:45 +02:00
|
|
|
void GroupInfo::SetConfig(Config * pconfig)
|
|
|
|
{
|
|
|
|
config = pconfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
Groups * GroupInfo::FindGroups(long dir_id)
|
|
|
|
{
|
|
|
|
GroupsWrap::iterator i = groups_wrap.find(dir_id);
|
|
|
|
|
|
|
|
if( i == groups_wrap.end() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return &(i->second.groups);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool GroupInfo::ParseGroups(const std::wstring & str, Groups & groups)
|
|
|
|
{
|
|
|
|
groups.Clear();
|
2012-01-12 03:24:08 +01:00
|
|
|
PT::Space & space = *groups.GetSpace();
|
2011-09-26 07:40:26 +02:00
|
|
|
conf_parser.SetSpace(space);
|
2011-10-16 23:33:45 +02:00
|
|
|
conf_parser.UTF8(config->utf8);
|
2011-09-26 07:40:26 +02:00
|
|
|
|
2012-01-12 03:24:08 +01:00
|
|
|
if( conf_parser.ParseString(str) == PT::ConfParser::ok )
|
2011-08-26 01:53:49 +02:00
|
|
|
{
|
2011-10-16 23:33:45 +02:00
|
|
|
groups.Reindex();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slog << logerror << "Syntax error in line: " << conf_parser.line << logend;
|
|
|
|
log << log1 << "Syntax error in line: " << conf_parser.line << logend;
|
|
|
|
groups.Clear();
|
2011-08-26 01:53:49 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 03:24:08 +01:00
|
|
|
return conf_parser.status == PT::ConfParser::ok;
|
2011-08-26 01:53:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GroupInfo::MarkAllGroupsToDelete()
|
|
|
|
{
|
|
|
|
GroupsWrap::iterator i = groups_wrap.begin();
|
|
|
|
|
|
|
|
for( ; i != groups_wrap.end() ; ++i)
|
|
|
|
i->second.to_delete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GroupInfo::DeleteAllMarkedGroups()
|
|
|
|
{
|
|
|
|
GroupsWrap::iterator inext;
|
|
|
|
GroupsWrap::iterator i = groups_wrap.begin();
|
|
|
|
|
|
|
|
while( i != groups_wrap.end() )
|
|
|
|
{
|
|
|
|
inext = i;
|
|
|
|
++inext;
|
|
|
|
|
|
|
|
if( i->second.to_delete )
|
|
|
|
{
|
|
|
|
log << log3 << "GroupItem: deleting group for dir id: " << i->first << logend;
|
|
|
|
groups_wrap.erase(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = inext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool GroupInfo::GetConfContent(const std::wstring & path)
|
|
|
|
{
|
|
|
|
int status = system->FollowAllLinks(path, config_dir_tab, config_file, false, false, false);
|
|
|
|
|
|
|
|
if( status != 1 )
|
|
|
|
{
|
|
|
|
log << log1 << "GroupItem: problem with reading a config file: " << path << ", status: " << status << logend;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if skip_existing_configs is true then only new config files will be parsed
|
|
|
|
void GroupInfo::ReadGroupsConf(Mounts & mounts, bool skip_existing_configs)
|
|
|
|
{
|
|
|
|
Mounts::MountTab::const_iterator i;
|
|
|
|
const Mounts::MountTab * mtab = mounts.GetMountTab();
|
|
|
|
|
|
|
|
// loop through all mount points
|
|
|
|
for(i=mtab->begin() ; i!=mtab->end() ; ++i)
|
|
|
|
{
|
|
|
|
const Mount & mount = i->second;
|
|
|
|
|
|
|
|
if( mount.param[mount_par_group_conf].defined &&
|
|
|
|
mount.param[mount_par_group_conf].arg.size() == 1 )
|
|
|
|
{
|
|
|
|
const std::wstring & file_name = mount.param[mount_par_group_conf].arg[0];
|
|
|
|
GroupsWrap::iterator c = groups_wrap.find(mount.dir_id);
|
|
|
|
bool exists = (c != groups_wrap.end() && c->second.file_name == file_name);
|
|
|
|
|
|
|
|
if( exists )
|
|
|
|
c->second.to_delete = false;
|
|
|
|
|
|
|
|
if( !(skip_existing_configs && exists) )
|
|
|
|
{
|
|
|
|
if( GetConfContent(file_name) )
|
|
|
|
{
|
|
|
|
log << log3 << "GroupItem: parsing conf file: " << config_file.url << logend;
|
|
|
|
groups_wrap[mount.dir_id].file_name = file_name;
|
|
|
|
|
|
|
|
if( !ParseGroups(config_file.content, groups_wrap[mount.dir_id].groups) )
|
|
|
|
groups_wrap[mount.dir_id].to_delete = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( exists )
|
|
|
|
c->second.to_delete = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if skip_existing_configs is true then only new config files will be parsed
|
|
|
|
void GroupInfo::ReadGroupsConfigs(bool skip_existing_configs)
|
|
|
|
{
|
|
|
|
MarkAllGroupsToDelete();
|
|
|
|
ReadGroupsConf(system->mounts, skip_existing_configs);
|
|
|
|
DeleteAllMarkedGroups();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|