int SMTPFileSystem::create(const char *path, mode_t mode, fuse_file_info *file_info) { const std::string tmp_path = m_tmp_files_pool.makeTmpPath(std::string(path)); int rval = ::creat(tmp_path.c_str(), mode); if (rval < 0) return -errno; file_info->fh = rval; m_tmp_files_pool.addFile(TypeTmpFile(std::string(path), tmp_path, rval, true)); m_device.filePush(tmp_path, std::string(path)); return 0; }
int SMTPFileSystem::open(const char *path, struct fuse_file_info *file_info) { if (file_info->flags & O_WRONLY) file_info->flags |= O_TRUNC; std::string tmp_file = m_tmp_files_pool.makeTmpPath(std::string(path)); int rval = m_device.filePull(std::string(path), tmp_file); if (rval != 0) return rval; int fd = ::open(tmp_file.c_str(), file_info->flags); if (fd < 0) return -errno; file_info->fh = fd; m_tmp_files_pool.addFile(TypeTmpFile(std::string(path), tmp_file, fd)); return 0; }
int SMTPFileSystem::open(const char *path, struct fuse_file_info *file_info) { if (file_info->flags & O_WRONLY) file_info->flags |= O_TRUNC; const std::string std_path(path); TypeTmpFile *tmp_file = const_cast<TypeTmpFile*>( m_tmp_files_pool.getFile(std_path)); std::string tmp_path; if (tmp_file) { tmp_path = tmp_file->pathTmp(); } else { tmp_path = m_tmp_files_pool.makeTmpPath(std_path); int rval = m_device.filePull(std_path, tmp_path); if (rval != 0) return -rval; } int fd = ::open(tmp_path.c_str(), file_info->flags); if (fd < 0) { ::unlink(tmp_path.c_str()); return -errno; } file_info->fh = fd; if (tmp_file) tmp_file->addFileDescriptor(fd); else m_tmp_files_pool.addFile(TypeTmpFile(std_path, tmp_path, fd)); return 0; }