MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / DeleteDir

Method DeleteDir

tensorflow/core/platform/hadoop/hadoop_file_system.cc:442–472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

440}
441
442Status HadoopFileSystem::DeleteDir(const string& dir) {
443 hdfsFS fs = nullptr;
444 TF_RETURN_IF_ERROR(Connect(dir, &fs));
445
446 // Count the number of entries in the directory, and only delete if it's
447 // non-empty. This is consistent with the interface, but note that there's
448 // a race condition where a file may be added after this check, in which
449 // case the directory will still be deleted.
450 int entries = 0;
451 hdfsFileInfo* info =
452 hdfs_->hdfsListDirectory(fs, TranslateName(dir).c_str(), &entries);
453 if (info != nullptr) {
454 hdfs_->hdfsFreeFileInfo(info, entries);
455 }
456 // Due to HDFS bug HDFS-8407, we can't distinguish between an error and empty
457 // folder, expscially for Kerberos enable setup, EAGAIN is quite common when
458 // the call is actually successful. Check again by Stat.
459 if (info == nullptr && errno != 0) {
460 FileStatistics stat;
461 TF_RETURN_IF_ERROR(Stat(dir, &stat));
462 }
463
464 if (entries > 0) {
465 return errors::FailedPrecondition("Cannot delete a non-empty directory.");
466 }
467 if (hdfs_->hdfsDelete(fs, TranslateName(dir).c_str(),
468 /*recursive=*/1) != 0) {
469 return IOError(dir, errno);
470 }
471 return Status::OK();
472}
473
474Status HadoopFileSystem::GetFileSize(const string& fname, uint64* size) {
475 hdfsFS fs = nullptr;

Callers 1

TEST_FFunction · 0.45

Calls 4

StatClass · 0.85
FailedPreconditionFunction · 0.85
IOErrorFunction · 0.85
c_strMethod · 0.80

Tested by 1

TEST_FFunction · 0.36