util/env.cc

filter: Statementstmt 65.7% 50 / 76 Branchbran 50.0% 22 / 44 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 60.0% 72 / 120 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« util/coding.cc ↑ Summary table/table_builder.cc »
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
4  
5 #include "leveldb/env.h"
6  
7 namespace leveldb {
8  
9 0 Env::~Env() {
10 0 }
11  
12 0 SequentialFile::~SequentialFile() {
13 0 }
14  
15 0 RandomAccessFile::~RandomAccessFile() {
16 0 }
17  
18 0 WritableFile::~WritableFile() {
19 0 }
20  
21 0 Logger::~Logger() {
22 0 }
23  
24 0 FileLock::~FileLock() {
25 0 }
26  
27 7 void Log(Logger* info_log, const char* format, ...) {
28 7 ▶ if (info_log != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (info_log != NULL) { 7 0 7
29 va_list ap;
30 7 va_start(ap, format);
31 7 ▶ info_log->Logv(format, ap);
Branch: 1 branch
BranchTrueFalseTotal
info_log->Logv(format, ap); 7 0 7
32 7 va_end(ap);
33 }
34 7 }
35  
36 5 Status WriteStringToFile(Env* env, const Slice& data,
37 const std::string& fname) {
38 WritableFile* file;
39 5 ▶ Status s = env->NewWritableFile(fname, &file);
Branch: 1 branch
BranchTrueFalseTotal
Status s = env->NewWritableFile(fname, &file); 5 0 5
40 5 ▶ if (!s.ok()) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s.ok()) { 0 5 5
41 0 return s;
42 }
43 5 ▶ s = file->Append(data);
Branch: 2 branches
BranchTrueFalseTotal
s = file->Append(data); 5 0 5
s = file->Append(data); 5 0 5
44 5 ▶ if (s.ok()) {
Branch: 1 branch
BranchTrueFalseTotal
if (s.ok()) { 5 0 5
45 5 ▶ s = file->Close();
Branch: 2 branches
BranchTrueFalseTotal
s = file->Close(); 5 0 5
s = file->Close(); 5 0 5
46 }
47 5 ▶ delete file; // Will auto-close if we did not close above
Branch: 1 branch
BranchTrueFalseTotal
delete file; // Will auto-close if we did not close above 5 0 5
48 5 ▶ if (!s.ok()) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s.ok()) { 0 5 5
49 0 ▶ env->DeleteFile(fname);
Branch: 1 branch
BranchTrueFalseTotal
env->DeleteFile(fname); 0 0 0
50 }
51 5 return s;
52 }
53  
54 3 Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
55 3 data->clear();
56 SequentialFile* file;
57 3 ▶ Status s = env->NewSequentialFile(fname, &file);
Branch: 1 branch
BranchTrueFalseTotal
Status s = env->NewSequentialFile(fname, &file); 3 0 3
58 3 ▶ if (!s.ok()) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s.ok()) { 0 3 3
59 0 return s;
60 }
61 static const int kBufferSize = 8192;
62 3 ▶ char* space = new char[kBufferSize];
Branch: 1 branch
BranchTrueFalseTotal
char* space = new char[kBufferSize]; 3 0 3
63 while (true) {
64 6 Slice fragment;
65 6 ▶ s = file->Read(kBufferSize, &fragment, space);
Branch: 2 branches
BranchTrueFalseTotal
s = file->Read(kBufferSize, &fragment, space); 6 0 6
s = file->Read(kBufferSize, &fragment, space); 6 0 6
66 6 ▶ if (!s.ok()) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s.ok()) { 0 6 6
67 0 break;
68 }
69 6 ▶ data->append(fragment.data(), fragment.size());
Branch: 1 branch
BranchTrueFalseTotal
data->append(fragment.data(), fragment.size()); 6 0 6
70 6 ▶ if (fragment.empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if (fragment.empty()) { 3 3 6
71 3 break;
72 }
73 3 }
74 3 ▶ delete[] space;
Branch: 1 branch
BranchTrueFalseTotal
delete[] space; 3 0 3
75 3 ▶ delete file;
Branch: 1 branch
BranchTrueFalseTotal
delete file; 3 0 3
76 3 return s;
77 }
78  
79 0 EnvWrapper::~EnvWrapper() {
80 0 }
81  
82 }
« util/coding.cc ↑ Summary table/table_builder.cc »