int FSTmp::Delete(FSPath& path, int* err, FSCInfo* info) { FSString* dName = path.GetItem(path.Count() - 1); FSTmpNode* n = rootDir.findByName(dName); if (n == 0) { return FS::SetError(err, FSTMP_ERROR_FILE_NOT_FOUND);; } else { /* if (n->nodeType == FSTmpNode::NODE_FILE) { // remove file at base FS int ret = baseFS->Delete(n->baseFSPath, err, info); if (ret != 0) return ret; } */ // remove from tmpfs list for (auto it = n->parentDir->content.begin(); it != n->parentDir->content.end(); ++it) { if ((*it).name.Cmp(*dName) == 0) { n->parentDir->content.erase(it); return FS::SetError(err, 0); } } return FS::SetError(err, FSTMP_ERROR_FILE_NOT_FOUND);; } }
void OperCFThread::CreateDirectory( FS* fs, FSPath& srcPath, FSPath& destPath, bool processMultipleFolders ) { if ( processMultipleFolders ) { const int DirIndex = srcPath.GetFirstUnmatchedItem( destPath ); FSPath Path; for ( int i = 0; i < destPath.Count(); i++ ) { // get next dir Path.PushStr( *destPath.GetItem( i ) ); int ret_err; // try to create dir if ( i >= DirIndex && fs->MkDir( Path, 0777, &ret_err, Info() ) ) { // skip "already exists" error if ( !fs->IsEEXIST( ret_err ) ) { throw_msg( "%s", fs->StrError( ret_err ).GetUtf8() ); } } } } else { int ret_err; if ( fs->MkDir( destPath, 0777, &ret_err, Info() ) ) { throw_msg( "%s", fs->StrError( ret_err ).GetUtf8() ); } } }
clPtr<FS> clArchPlugin::OpenFS( clPtr<FS> Fs, FSPath& Path ) const { FSString Uri = Fs->Uri( Path ); struct archive* Arch = ArchOpen( Uri.GetUtf8() ); if ( Arch == nullptr ) { return nullptr; } FSArchNode RootDir; RootDir.fsStat.mode = S_IFDIR; FSPath NodePath; struct archive_entry* entry = archive_entry_new2( Arch ); int Res; while ( ( Res = archive_read_next_header2( Arch, entry ) ) == ARCHIVE_OK ) { NodePath.Set( CS_UTF8, archive_entry_pathname( entry ) ); FSString* ItemName = NodePath.GetItem( NodePath.Count() - 1 ); if ( NodePath.Count() == 1 && ( ItemName->IsDot() || ItemName->IsEmpty() ) ) { // skip root dir continue; } const mode_t Mode = archive_entry_mode( entry ); const int64_t Size = archive_entry_size( entry ); RootDir.entryOffset += Size; FSStat ItemStat; ItemStat.mode = S_ISREG( Mode ) ? Mode : S_IFDIR; ItemStat.size = Size; ItemStat.m_CreationTime = archive_entry_ctime( entry ); ItemStat.m_LastAccessTime = archive_entry_atime( entry ); ItemStat.m_LastWriteTime = archive_entry_mtime( entry ); ItemStat.m_ChangeTime = ItemStat.m_LastWriteTime; FSArchNode* Dir = ArchGetParentDir( &RootDir, NodePath, ItemStat ); FSArchNode* Item = Dir->Add( FSArchNode( ItemName->GetUtf8(), ItemStat ) ); if (Item) { Item->entryOffset = archive_read_header_position( Arch ); } } if ( Res != ARCHIVE_EOF ) { dbg_printf( "Couldn't read archive entry: %s\n", archive_error_string( Arch ) ); } archive_entry_free( entry ); ArchClose( Arch ); return new FSArch( RootDir, Uri ); }
int FSTmp::MkDir(FSPath& path, int mode, int* err, FSCInfo* info) { FSPath parentPath; parentPath.Copy(path, path.Count() - 1); FSTmpNode* parent = rootDir.findByFsPath(&parentPath); if (!parent) return SetError(err, FSTMP_ERROR_FILE_NOT_FOUND); FSTmpNode* parentDir = parent; FSTmpNode fsTmpNode(path.GetItem(path.Count() - 1)->GetUnicode(), parentDir); parentDir->Add(&fsTmpNode); return SetError(err, 0); }
static void stripPathFromLastItem(FSPath& path) { FSString* lastItem = path.GetItem(path.Count() - 1); if (lastItem) { const unicode_t* lastU = lastItem->GetUnicode(); const unicode_t* lastDelim = unicode_strrchr(lastU, DIR_SPLITTER); if (lastDelim != 0) { path.SetItemStr(path.Count() - 1,FSString(lastDelim + 1)); } } }
int FSTmp::RmDir(FSPath& path, int* err, FSCInfo* info) { FSTmpNode* n = rootDir.findByFsPath(&path); FSString* dirName = path.GetItem(path.Count() - 1); for (auto it = n->parentDir->content.begin(); it != n->parentDir->content.end(); ++it) { if ((*it).name.Cmp(*dirName) == 0) { n->parentDir->content.erase(it); return FS::SetError(err, 0); } } return FS::SetError(err, FSTMP_ERROR_FILE_NOT_FOUND); }
int FSTmp::Rename(FSPath& oldpath, FSPath& newpath, int* err, FSCInfo* info) { FSTmpNode* n = rootDir.findByName(oldpath.GetItem(oldpath.Count() - 1)); if (n == 0) { return FS::SetError(err, FSTMP_ERROR_FILE_NOT_FOUND); } else { if (n->nodeType == FSTmpNode::NODE_FILE) { int ret = baseFS->Rename(n->baseFSPath, newpath, err, info); if (ret != 0) return ret; n->name = newpath.GetUnicode(); return SetError(err, 0); } else {// XXX ??? add case when new and old path are in different dirs ((FSTmpNode*)(n))->name = *newpath.GetItem(newpath.Count() - 1); return SetError(err, 0); } } }
int FSTmp::SetFileTime(FSPath& path, FSTime cTime, FSTime aTime, FSTime mTime, int* err, FSCInfo* info) { FSTmpNode* fsTemp = rootDir.findByName(path.GetItem(path.Count() - 1)); if (fsTemp == 0) { return FS::SetError(err, FSTMP_ERROR_FILE_NOT_FOUND); } else { fsTemp->fsStat.m_CreationTime = cTime; fsTemp->fsStat.m_LastAccessTime = aTime; fsTemp->fsStat.m_LastWriteTime = mTime; fsTemp->fsStat.m_ChangeTime = mTime; if (fsTemp->nodeType == FSTmpNode::NODE_FILE) return baseFS->SetFileTime(fsTemp->baseFSPath, cTime, aTime, mTime, err, info); else return FS::SetError(err, 0); } }
clPtr<FS> ParzeURI( const unicode_t* uri, FSPath& path, clPtr<FS>* checkFS, int count ) { #ifdef LIBSMBCLIENT_EXIST if ( uri[0] == 's' && uri[1] == 'm' && uri[2] == 'b' && uri[3] == ':' && uri[4] == '/' && uri[5] == '/' ) { return ParzeSmbURI( uri + 6, path, checkFS, count ); } #endif if ( uri[0] == 'f' && uri[1] == 't' && uri[2] == 'p' && uri[3] == ':' && uri[4] == '/' && uri[5] == '/' ) { return ParzeFtpURI( uri + 6, path, checkFS, count ); } #if defined(LIBSSH_EXIST) || defined(LIBSSH2_EXIST) if ( uri[0] == 's' && uri[1] == 'f' && uri[2] == 't' && uri[3] == 'p' && uri[4] == ':' && uri[5] == '/' && uri[6] == '/' ) { return ParzeSftpURI( uri + 7, path, checkFS, count ); } #endif if ( uri[0] == 'f' && uri[1] == 'i' && uri[2] == 'l' && uri[3] == 'e' && uri[4] == ':' && uri[5] == '/' && uri[6] == '/' ) { uri += 6; //оставляем 1 символ '/' } #ifdef _WIN32 int c = uri[0]; if ( c == '\\' || c == '/' ) { if ( uri[1] == '/' || uri[1] == '\\' ) { FSString link = uri + 1; if ( !ParzeLink( path, link ) ) { return clPtr<FS>(); } if ( path.Count() == 1 ) { clPtr<FS> netFs = new FSWin32Net( 0 ); path.Set( CS_UTF8, "/" ); return netFs; } if ( path.Count() == 2 ) { static unicode_t aa[] = {'\\', '\\', 0}; std::vector<wchar_t> name = UnicodeToUtf16( carray_cat<unicode_t>( aa, path.GetItem( 1 )->GetUnicode() ).data() ); NETRESOURCEW r; r.dwScope = RESOURCE_GLOBALNET; r.dwType = RESOURCETYPE_ANY; r.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC; r.dwUsage = RESOURCEUSAGE_CONTAINER; r.lpLocalName = 0; r.lpRemoteName = name.data(); r.lpComment = 0; r.lpProvider = 0; clPtr<FS> netFs = new FSWin32Net( &r ); path.Set( CS_UTF8, "/" ); return netFs; } return new FSSys( -1 ); } FSString link = uri; if ( !ParzeLink( path, link ) ) { return clPtr<FS>(); } return ( count > 0 && !checkFS[0].IsNull() ) ? checkFS[0] : clPtr<FS>(); } if ( c >= 'A' && c <= 'Z' ) { c = c - 'A' + 'a'; } if ( c < 'a' || c > 'z' || uri[1] != ':' || ( uri[2] != '/' && uri[2] != '\\' ) ) { FSString link = uri; if ( !ParzeLink( path, link ) ) { return clPtr<FS>(); } return ( count > 0 && !checkFS[0].IsNull() ) ? checkFS[0] : clPtr<FS>(); } FSString link = uri + 2; if ( !ParzeLink( path, link ) ) { return clPtr<FS>(); } return new FSSys( c - 'a' ); #else FSString link = uri; if ( !ParzeLink( path, link ) ) { return clPtr<FS>(); } if ( uri[0] != '/' ) { return ( count > 0 && !checkFS[0].IsNull() ) ? checkFS[0] : clPtr<FS>(); } return new FSSys(); //systemclPtr<FS>; #endif }