@@ -308,9 +308,9 @@ static void SetPathInfo(const hdfsFileInfo* input, HdfsPathInfo* out) {
308308}
309309
310310// Private implementation
311- class HdfsClient ::HdfsClientImpl {
311+ class HadoopFileSystem ::HadoopFileSystemImpl {
312312 public:
313- HdfsClientImpl () {}
313+ HadoopFileSystemImpl () {}
314314
315315 Status Connect (const HdfsConnectionConfig* config) {
316316 if (config->driver == HdfsDriver::LIBHDFS3 ) {
@@ -396,6 +396,24 @@ class HdfsClient::HdfsClientImpl {
396396 return Status::OK ();
397397 }
398398
399+ Status Stat (const std::string& path, FileStatistics* stat) {
400+ HdfsPathInfo info;
401+ RETURN_NOT_OK (GetPathInfo (path, &info));
402+
403+ stat->size = info.size ;
404+ stat->kind = info.kind ;
405+ return Status::OK ();
406+ }
407+
408+ Status GetChildren (const std::string& path, std::vector<std::string>* listing) {
409+ std::vector<HdfsPathInfo> detailed_listing;
410+ RETURN_NOT_OK (ListDirectory (path, &detailed_listing));
411+ for (const auto & info : detailed_listing) {
412+ listing->push_back (info.name );
413+ }
414+ return Status::OK ();
415+ }
416+
399417 Status ListDirectory (const std::string& path, std::vector<HdfsPathInfo>* listing) {
400418 int num_entries = 0 ;
401419 hdfsFileInfo* entries = driver_->ListDirectory (fs_, path.c_str (), &num_entries);
@@ -476,6 +494,18 @@ class HdfsClient::HdfsClientImpl {
476494 return Status::OK ();
477495 }
478496
497+ Status Chmod (const std::string& path, int mode) {
498+ int ret = driver_->Chmod (fs_, path.c_str (), static_cast <short >(mode)); // NOLINT
499+ CHECK_FAILURE (ret, " Chmod" );
500+ return Status::OK ();
501+ }
502+
503+ Status Chown (const std::string& path, const char * owner, const char * group) {
504+ int ret = driver_->Chown (fs_, path.c_str (), owner, group);
505+ CHECK_FAILURE (ret, " Chown" );
506+ return Status::OK ();
507+ }
508+
479509 private:
480510 LibHdfsShim* driver_;
481511
@@ -490,68 +520,92 @@ class HdfsClient::HdfsClientImpl {
490520// ----------------------------------------------------------------------
491521// Public API for HDFSClient
492522
493- HdfsClient::HdfsClient () { impl_.reset (new HdfsClientImpl ()); }
523+ HadoopFileSystem::HadoopFileSystem () { impl_.reset (new HadoopFileSystemImpl ()); }
494524
495- HdfsClient ::~HdfsClient () {}
525+ HadoopFileSystem ::~HadoopFileSystem () {}
496526
497- Status HdfsClient ::Connect (const HdfsConnectionConfig* config,
498- std::shared_ptr<HdfsClient >* fs) {
527+ Status HadoopFileSystem ::Connect (const HdfsConnectionConfig* config,
528+ std::shared_ptr<HadoopFileSystem >* fs) {
499529 // ctor is private, make_shared will not work
500- *fs = std::shared_ptr<HdfsClient >(new HdfsClient ());
530+ *fs = std::shared_ptr<HadoopFileSystem >(new HadoopFileSystem ());
501531
502532 RETURN_NOT_OK ((*fs)->impl_ ->Connect (config));
503533 return Status::OK ();
504534}
505535
506- Status HdfsClient ::MakeDirectory (const std::string& path) {
536+ Status HadoopFileSystem ::MakeDirectory (const std::string& path) {
507537 return impl_->MakeDirectory (path);
508538}
509539
510- Status HdfsClient ::Delete (const std::string& path, bool recursive) {
540+ Status HadoopFileSystem ::Delete (const std::string& path, bool recursive) {
511541 return impl_->Delete (path, recursive);
512542}
513543
514- Status HdfsClient::Disconnect () { return impl_->Disconnect (); }
544+ Status HadoopFileSystem::DeleteDirectory (const std::string& path) {
545+ return Delete (path, true );
546+ }
547+
548+ Status HadoopFileSystem::Disconnect () { return impl_->Disconnect (); }
515549
516- bool HdfsClient ::Exists (const std::string& path) { return impl_->Exists (path); }
550+ bool HadoopFileSystem ::Exists (const std::string& path) { return impl_->Exists (path); }
517551
518- Status HdfsClient ::GetPathInfo (const std::string& path, HdfsPathInfo* info) {
552+ Status HadoopFileSystem ::GetPathInfo (const std::string& path, HdfsPathInfo* info) {
519553 return impl_->GetPathInfo (path, info);
520554}
521555
522- Status HdfsClient::GetCapacity (int64_t * nbytes) { return impl_->GetCapacity (nbytes); }
556+ Status HadoopFileSystem::Stat (const std::string& path, FileStatistics* stat) {
557+ return impl_->Stat (path, stat);
558+ }
559+
560+ Status HadoopFileSystem::GetCapacity (int64_t * nbytes) {
561+ return impl_->GetCapacity (nbytes);
562+ }
563+
564+ Status HadoopFileSystem::GetUsed (int64_t * nbytes) { return impl_->GetUsed (nbytes); }
523565
524- Status HdfsClient::GetUsed (int64_t * nbytes) { return impl_->GetUsed (nbytes); }
566+ Status HadoopFileSystem::GetChildren (const std::string& path,
567+ std::vector<std::string>* listing) {
568+ return impl_->GetChildren (path, listing);
569+ }
525570
526- Status HdfsClient ::ListDirectory (const std::string& path,
527- std::vector<HdfsPathInfo>* listing) {
571+ Status HadoopFileSystem ::ListDirectory (const std::string& path,
572+ std::vector<HdfsPathInfo>* listing) {
528573 return impl_->ListDirectory (path, listing);
529574}
530575
531- Status HdfsClient ::OpenReadable (const std::string& path, int32_t buffer_size,
532- std::shared_ptr<HdfsReadableFile>* file) {
576+ Status HadoopFileSystem ::OpenReadable (const std::string& path, int32_t buffer_size,
577+ std::shared_ptr<HdfsReadableFile>* file) {
533578 return impl_->OpenReadable (path, buffer_size, file);
534579}
535580
536- Status HdfsClient ::OpenReadable (const std::string& path,
537- std::shared_ptr<HdfsReadableFile>* file) {
581+ Status HadoopFileSystem ::OpenReadable (const std::string& path,
582+ std::shared_ptr<HdfsReadableFile>* file) {
538583 return OpenReadable (path, kDefaultHdfsBufferSize , file);
539584}
540585
541- Status HdfsClient ::OpenWriteable (const std::string& path, bool append,
542- int32_t buffer_size, int16_t replication,
543- int64_t default_block_size,
544- std::shared_ptr<HdfsOutputStream>* file) {
586+ Status HadoopFileSystem ::OpenWriteable (const std::string& path, bool append,
587+ int32_t buffer_size, int16_t replication,
588+ int64_t default_block_size,
589+ std::shared_ptr<HdfsOutputStream>* file) {
545590 return impl_->OpenWriteable (path, append, buffer_size, replication, default_block_size,
546591 file);
547592}
548593
549- Status HdfsClient ::OpenWriteable (const std::string& path, bool append,
550- std::shared_ptr<HdfsOutputStream>* file) {
594+ Status HadoopFileSystem ::OpenWriteable (const std::string& path, bool append,
595+ std::shared_ptr<HdfsOutputStream>* file) {
551596 return OpenWriteable (path, append, 0 , 0 , 0 , file);
552597}
553598
554- Status HdfsClient::Rename (const std::string& src, const std::string& dst) {
599+ Status HadoopFileSystem::Chmod (const std::string& path, int mode) {
600+ return impl_->Chmod (path, mode);
601+ }
602+
603+ Status HadoopFileSystem::Chown (const std::string& path, const char * owner,
604+ const char * group) {
605+ return impl_->Chown (path, owner, group);
606+ }
607+
608+ Status HadoopFileSystem::Rename (const std::string& src, const std::string& dst) {
555609 return impl_->Rename (src, dst);
556610}
557611
0 commit comments