leveldb
Classes | Functions
leveldb::anonymous_namespace{fault_injection_test.cc} Namespace Reference

Classes

struct  FileState
 

Functions

static std::string GetDirName (const std::string filename)
 
Status SyncDir (const std::string &dir)
 
Status Truncate (const std::string &filename, uint64_t length)
 

Function Documentation

§ GetDirName()

static std::string leveldb::anonymous_namespace{fault_injection_test.cc}::GetDirName ( const std::string  filename)
static

Definition at line 37 of file fault_injection_test.cc.

37  {
38  size_t found = filename.find_last_of("/\\");
39  if (found == std::string::npos) {
40  return "";
41  } else {
42  return filename.substr(0, found);
43  }
44 }
Here is the caller graph for this function:

§ SyncDir()

Status leveldb::anonymous_namespace{fault_injection_test.cc}::SyncDir ( const std::string &  dir)

Definition at line 46 of file fault_injection_test.cc.

46  {
47  // As this is a test it isn't required to *actually* sync this directory.
48  return Status::OK();
49 }
Here is the call graph for this function:
Here is the caller graph for this function:

§ Truncate()

Status leveldb::anonymous_namespace{fault_injection_test.cc}::Truncate ( const std::string &  filename,
uint64_t  length 
)

Definition at line 52 of file fault_injection_test.cc.

52  {
54 
55  SequentialFile* orig_file;
56  Status s = env->NewSequentialFile(filename, &orig_file);
57  if (!s.ok())
58  return s;
59 
60  char* scratch = new char[length];
61  leveldb::Slice result;
62  s = orig_file->Read(length, &result, scratch);
63  delete orig_file;
64  if (s.ok()) {
65  std::string tmp_name = GetDirName(filename) + "/truncate.tmp";
66  WritableFile* tmp_file;
67  s = env->NewWritableFile(tmp_name, &tmp_file);
68  if (s.ok()) {
69  s = tmp_file->Append(result);
70  delete tmp_file;
71  if (s.ok()) {
72  s = env->RenameFile(tmp_name, filename);
73  } else {
74  env->DeleteFile(tmp_name);
75  }
76  }
77  }
78 
79  delete[] scratch;
80 
81  return s;
82 }
virtual Status NewWritableFile(const std::string &fname, WritableFile **result)=0
static std::string GetDirName(const std::string filename)
virtual Status RenameFile(const std::string &src, const std::string &target)=0
virtual Status NewSequentialFile(const std::string &fname, SequentialFile **result)=0
static Env * Default()
Definition: env_posix.cc:613
virtual Status DeleteFile(const std::string &fname)=0
Here is the call graph for this function:
Here is the caller graph for this function: