int FuseContext::rmdir (const char *path) { namespace fs = boost::filesystem; Path_t wrapped = m_realRoot / path; // first we make sure that the parent directory exists Path_t parent = wrapped.parent_path(); Path_t filename = wrapped.filename(); if( !fs::exists(parent) ) return -ENOENT; // unlink the directory holding the file contents, the meta file, // and the staged file fs::remove_all( wrapped ); try { // remove the entry from the parent m_backend->db().unlink( Path_t(path) ); } catch( const std::exception& ex ) { std::cerr << "FuseContext::rmdir: " << "\n path: " << path << "\n real: " << wrapped << "\n err: " << ex.what() << "\n"; } return 0; }
int FuseContext::mkdir (const char *path, mode_t mode) { namespace fs = boost::filesystem; Path_t wrapped = m_realRoot / path; // first we make sure that the parent directory exists Path_t parent = wrapped.parent_path(); Path_t filename = wrapped.filename(); if( !fs::exists(parent) ) return -ENOENT; try { m_backend->db().mknod( Path_t(path) ); } catch( const std::exception& ex ) { std::cerr << "FuseContext::mkdir: " << "\n path: " << path << "\n real: " << wrapped << "\n err: " << ex.what() << "\n"; return -EINVAL; } // create the directory int result = ::mkdir( wrapped.c_str(), mode ); if( result ) return -errno; return 0; }
int FuseContext::open (const char *path, struct fuse_file_info *fi) { namespace fs = boost::filesystem; Path_t wrapped = m_realRoot / path; // first we make sure that the file exists Path_t parent = wrapped.parent_path(); Path_t filename = wrapped.filename(); if( !fs::exists(parent) ) return -ENOENT; // make sure that the file exists, if it doesn't exist check for the // O_CREAT flag if( !fs::exists(wrapped) ) { if( fi->flags | O_CREAT ) return this->create(path,0777,fi); else return -EEXIST; } // open the file int result = ::open( wrapped.c_str(), fi->flags ); if( result < 0 ) return -errno; // create a file descriptor for the opened file int os_fd = result; int my_fd = -1; try { my_fd = m_openedFiles.registerFile( Path_t(path) ,os_fd); result = 0; } catch( const std::exception& ex ) { my_fd = -1; result = -ENOMEM; ::close(os_fd); std::cerr << "FuseContext::open" << "\n path: " << path << "\n real: " << wrapped << "\n err: " << ex.what(); } fi->fh = my_fd; return result; }
MetaFile::MetaFile( const Path_t& path ) { namespace fs = boost::filesystem; Path_t metapath; if( fs::is_directory(path) ) { metapath = path / "obfs.sqlite"; m_subpath = "."; } else { metapath = path.parent_path() / "obfs.sqlite"; m_subpath = path.filename().string(); } m_sql.open( soci::sqlite3, metapath.string() ); }
int FuseContext::create (const char *path, mode_t mode, struct fuse_file_info *fi) { namespace fs = boost::filesystem; Path_t wrapped = (m_realRoot / path); // first we make sure that the parent directory exists Path_t parent = wrapped.parent_path(); Path_t filename = wrapped.filename(); if( !fs::exists(parent) || !fs::is_directory(parent) ) return -ENOENT; // create the local version of the file int result = ::creat( wrapped.c_str(), mode ); if( result < 0 ) return -errno; // create a file descriptor for the opened file int os_fd = result; int my_fd = -1; try { // add an entry to the directory listing m_backend->db().mknod( Path_t(path) ); my_fd = m_openedFiles.registerFile( Path_t(path) ,os_fd); result = 0; } catch( const std::exception& ex ) { my_fd = -1; result = -EIO; ::close(os_fd); std::cerr << "FuseContext::create: " << "\n path: " << path << "\n real: " << wrapped << "\n mode: " << std::hex << mode << std::dec << "\n"; } fi->fh = my_fd; return result; }
int FuseContext::mknod (const char *path, mode_t mode, dev_t dev) { namespace fs = boost::filesystem; Path_t wrapped = (m_realRoot / path); // we do not allow special files if( mode & ( S_IFCHR | S_IFBLK ) ) return -EINVAL; // first we make sure that the parent directory exists Path_t parent = wrapped.parent_path(); Path_t filename = wrapped.filename(); if( !fs::exists(parent) || !fs::is_directory(parent) ) return -ENOENT; // create the local version of the file int result = ::mknod( wrapped.c_str(), mode, 0 ); if( result ) return -errno; // add an entry to the directory listing try { mode_t modeMask = 0777; mode_t typeMask = ~modeMask; m_backend->db().mknod( Path_t(path) ); } catch( const std::exception& ex ) { std::cerr << "FuseContext::mknod: " << "\n path: " << path << "\n real: " << wrapped << "\n err: " << ex.what() << "\n"; } return 0; }
bool rab::CreateDiffFile( Options const& options, DiffEncoders const &diffEncoders, FileInfo& fileInfo, Path_t const& fullNew, Path_t const& fullOld, Path_t const& relativeTemp, dung::MemoryBlock const& newFile, dung::MemoryBlock const& oldFile, PackageOutput_t &package, LogOutput_t& out ) { Path_t fullTemp = relativeTemp.filename(); if( options.produceTemp ) { fullTemp = options.pathToTemp / relativeTemp; fs::create_directories( fullTemp.parent_path() ); } dung::DiffEncoder_i* pEncoder = diffEncoders.FindEncoder( fileInfo.name, fileInfo.diffMethod ); if( pEncoder != NULL ) { out << "Encoding " << fileInfo.diffMethod << " diff file " << GenericString( relativeTemp ) << std::endl; dung::MemoryBlock deltaFile; if( !pEncoder->EncodeDiffMemoryBlock( newFile.pBlock, newFile.size, oldFile.pBlock, oldFile.size, deltaFile.pBlock, deltaFile.size ) ) { _tstring errorMessage; pEncoder->GetErrorMessage( errorMessage ); out << "Encoding error: " << errorMessage << std::endl; return false; } if( options.produceTemp ) { if( !WriteWholeFile( fullTemp.wstring(), deltaFile ) ) { out << "Can't write file " << GenericString( fullTemp ) << std::endl; return false; } } if( !package.WriteFile( GenericString( relativeTemp ), deltaFile.pBlock, deltaFile.size ) ) { out << "Can't write file " << GenericString( relativeTemp ) << " to package. Size=" << deltaFile.size << std::endl; return false; } } else { dung::DiffEncoderExternal_i* pExternalEncoder = diffEncoders.FindExternalEncoder( fileInfo.name, fileInfo.diffMethod ); if( pExternalEncoder != NULL ) { out << "Encoding " << fileInfo.diffMethod << " diff file " << GenericString( relativeTemp ) << std::endl; if( !pExternalEncoder->EncodeDiffFile( GenericString(fullNew).c_str(), GenericString(fullOld).c_str(), GenericString(fullTemp).c_str() ) ) { _tstring errorMessage; pExternalEncoder->GetErrorMessage( errorMessage ); out << "Encoding error: " << errorMessage << std::endl; return false; } dung::MemoryBlock deltaFile; if( !ReadWholeFile( fullTemp.generic_string(), deltaFile ) ) { out << "Can't read file " << GenericString(fullTemp) << std::endl; return false; } if( !options.produceTemp ) fs::remove( fullTemp ); if( !package.WriteFile( GenericString(relativeTemp), deltaFile.pBlock, deltaFile.size ) ) { out << "Can't write file " << GenericString(relativeTemp) << " to package. Size=" << deltaFile.size << std::endl; return false; } } else { out << "Can't file encoder for file " << fileInfo.name << std::endl; return false; } } return true; }