changed organization of static files

removed: item.auth item.auth_path
added:   item.file_path, item.file_fs, item.file_type
now the path to a static file is a relative path
added: thumbnails (not finished yet)
fixed: db didn't correctly return the number of deleted items /DelItem() method/




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@696 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-12-10 21:07:01 +00:00
parent 9b29cce1a4
commit 36c8822e6c
41 changed files with 435 additions and 364 deletions

View File

@@ -392,31 +392,30 @@ return puser->IsMemberOf(group);
bool System::MakePathSimpleFs(std::wstring & path, long dir_id, bool create_dir)
// the path depends on parent_id
bool System::CreateNewFileSimpleFs(Item & item)
{
if( config->auth_simplefs_dir.empty() )
bool res = dirs.MakePath(item.parent_id, item.file_path);
if( res )
{
log << log1 << "System: auth_simplefs_dir is not set in the config file" << logend;
return false;
if( !item.file_path.empty() && item.file_path[0] == '/' )
item.file_path.erase(0, 1);
}
else
{
log << log1 << "System: CreateNewFileSimpleFs: can't create a path to item.id: " << item.id
<< ", item.parent_id: " << item.parent_id << logend;
}
if( !dirs.MakePath(dir_id, path) )
return false;
if( create_dir && !CreateDirs(config->auth_simplefs_dir, path, 0755) )
return false;
path.insert(0, config->auth_simplefs_dir);
return true;
return res;
}
// the path depends on id
bool System::MakePathHashFs(std::wstring & path, long id, bool create_dir)
bool System::CreateNewFileHashFs(Item & item)
{
wchar_t buffer[50];
wchar_t * hash = buffer;
@@ -424,79 +423,112 @@ size_t buffer_len = sizeof(buffer)/sizeof(wchar_t);
// get 'id' as hexadecimal
buffer[0] = '0';
swprintf(buffer+1, buffer_len, L"%lx", (unsigned long)id);
swprintf(buffer+1, buffer_len, L"%lx", (unsigned long)item.id);
path = config->auth_hashfs_dir;
if( path.empty() )
{
log << log1 << "System: auth_hashfs_dir is not set in the config file" << logend;
return false;
}
path += '/';
item.file_path.clear();
// make sure that the length is even
if( (wcslen(hash) & 1) != 0 )
hash = buffer + 1; // the first character was zero
// creating dirs without the last part
// the last part is a part of a file
for(size_t i=0 ; hash[i] != 0 ; i+=2)
{
path += hash[i];
path += hash[i+1];
item.file_path += hash[i];
item.file_path += hash[i+1];
if( hash[i+2] != 0 )
{
if( create_dir && !CreateDir(path, 0755) )
return false;
path += '/';
}
item.file_path += '/';
}
// one character more to make sure the path is unique
// (we can have a directory without the character)
path += '_';
item.file_path += '_';
return true;
}
// making a complete path to a static file
bool System::MakePath(const Item & item, std::wstring & path, bool create_dir)
// creating item.file_path and item.file_fs
// you should set file_type yourself
// this method uses: item.id, item.url, item.parent_id (for selecting a mountpoint)
bool System::CreateNewFile(Item & item)
{
bool res;
if( item.type != Item::file )
{
log << log1 << "System: CreateNewFile: the item should be a file" << logend;
return false;
}
Mount * pmount = mounts.CalcMount(item.parent_id);
if( !pmount || pmount->fs == mounts.MountFsSimplefs() )
if( !pmount || pmount->fs != mounts.MountFsHashfs() )
{
res = MakePathSimpleFs(path, item.parent_id, create_dir);
res = CreateNewFileSimpleFs(item);
item.file_fs = mounts.MountFsSimplefs();
}
else
{
res = MakePathHashFs(path, item.id, create_dir);
res = CreateNewFileHashFs(item);
item.file_fs = mounts.MountFsHashfs();
}
if( res )
path += item.url;
item.file_path += item.url;
else
path.clear();
item.file_path.clear();
return res;
}
bool System::MakePath(Item & item, bool create_dir)
// making a global file path
// you should call CreateNewFile before
bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bool create_dir, int chmod)
{
return MakePath(item, item.auth_path, create_dir);
path.clear();
if( config->upload_dir.empty() )
{
log << log1 << "System: MakePath: upload_dir is not set in the config file" << logend;
return false;
}
if( item.file_path.empty() || item.file_type == WINIX_ITEM_FILETYPE_NONE )
{
log << log1 << "System: MakePath: this item has not a static file" << logend;
return false;
}
path = config->upload_dir;
if( item.file_fs == mounts.MountFsHashfs() )
path += L"/hashfs";
else
path += L"/simplefs";
if( thumb )
path += L"/thumb";
else
path += L"/normal";
if( create_dir && !CreateDirs(path, item.file_path, chmod, true) )
return false;
path += '/';
path += item.file_path;
return true;
}
Error System::AddFile(Item & item, int notify_code)
{
if( item.type == Item::dir )