void dir_cpi_impl::sync_open_dir (saga::filesystem::directory & ret, saga::url name_to_open, int openmode) { instance_data idata (this); bool exists = false; bool is_dir = false; saga::url file_url(idata->location_); boost::filesystem::path name (name_to_open.get_path(), boost::filesystem::native); boost::filesystem::path path (file_url.get_path(), boost::filesystem::native); if ( ! name.has_root_path () ) { path /= name; file_url.set_path(path.string()); } else { path = name; file_url = saga::url(name.string()); } if(fs_->Exists(path.string().c_str())) { exists = true; //Check to see if it is a directory if(fs_->IsDirectory(path.string().c_str())) is_dir = true; } if ( exists && !is_dir) { SAGA_ADAPTOR_THROW(path.string() + ": doesn't refer to a file object", saga::DoesNotExist); } ret = saga::filesystem::directory (this->get_proxy()->get_session(), file_url.get_url(), openmode); //SAGA_ADAPTOR_THROW ("Not Implemented", saga::NotImplemented); }
void TextRecordReader::Initialize(InputChunk* chunk) { // Open file. FileInputChunk* file_chunk = dynamic_cast<FileInputChunk*>(chunk); saga::url file_url(file_chunk->path()); SagaFileInputStream* file_input = new SagaFileInputStream(file_url, saga::filesystem::Read); // Seek to the beginning of the chunk. file_offset_ = file_chunk->start_offset(); end_offset_ = file_offset_ + file_chunk->GetLength(); // Adjust offset if necessary. bool skip_first_line = false; if (file_offset_ > 0) { skip_first_line = true; --file_offset_; } file_input->Skip(file_offset_); CopyingInputStreamAdaptor* adaptor = new CopyingInputStreamAdaptor( file_input); // The adaptor should free the CopyingStream. adaptor->SetOwnsCopyingStream(true); input_stream_.reset(adaptor); reader_.reset(new LineReader(input_stream_.get())); if (skip_first_line) { file_offset_ += reader_->ReadLine(&line_); } }
void test_clone_local__should_clone_local(void) { git_buf buf = GIT_BUF_INIT; /* we use a fixture path because it needs to exist for us to want to clone */ const char *path = cl_fixture("testrepo.git"); cl_git_pass(file_url(&buf, "", path)); cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO)); cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL)); cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS)); cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL)); cl_git_pass(file_url(&buf, "localhost", path)); cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO)); cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL)); cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS)); cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL)); cl_git_pass(file_url(&buf, "other-host.mycompany.com", path)); cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO)); cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL)); cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS)); cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL)); /* Ensure that file:/// urls are percent decoded: .git == %2e%67%69%74 */ cl_git_pass(file_url(&buf, "", path)); git_buf_shorten(&buf, 4); cl_git_pass(git_buf_puts(&buf, "%2e%67%69%74")); cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO)); cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL)); cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS)); cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL)); cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_AUTO)); cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL)); cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_NO_LINKS)); cl_assert_equal_i(0, git_clone__should_clone_local(path, GIT_CLONE_NO_LOCAL)); git_buf_free(&buf); }