Skip to content

Commit

Permalink
Revert 239280 "Move more file_util functions to base namespace."
Browse files Browse the repository at this point in the history
dbus_unittests started fialing on Linux Tests (dbg)(2) and Linux Tests (dbg)(2)(32).
This CL is the only in the intersection of CLs in the first failing build on
the two builders, so giving a speculative revert a try (rlarocque already
tried a clobber, it didn't help).

http://build.chromium.org/p/chromium.linux/builders/Linux%20Tests%20%28dbg%29%282%29/builds/41806
http://build.chromium.org/p/chromium.linux/builders/Linux%20Tests%20%28dbg%29%282%29%2832%29/builds/8544


> Move more file_util functions to base namespace.
> 
> TBR=sky
> 
> Review URL: https://codereview.chromium.org/109043002

TBR=brettw@chromium.org

Review URL: https://codereview.chromium.org/105823009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239400 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
thakis@chromium.org committed Dec 8, 2013
1 parent 76b4b15 commit a4f7378
Show file tree
Hide file tree
Showing 80 changed files with 317 additions and 295 deletions.
12 changes: 6 additions & 6 deletions base/event_recorder_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool EventRecorder::StartRecording(const FilePath& filename) {

// Open the recording file.
DCHECK(!file_);
file_ = OpenFile(filename, "wb+");
file_ = file_util::OpenFile(filename, "wb+");
if (!file_) {
DLOG(ERROR) << "EventRecorder could not open log file";
return false;
Expand All @@ -63,7 +63,7 @@ bool EventRecorder::StartRecording(const FilePath& filename) {
GetModuleHandle(NULL), 0);
if (!journal_hook_) {
DLOG(ERROR) << "EventRecorder Record Hook failed";
CloseFile(file_);
file_util::CloseFile(file_);
return false;
}

Expand All @@ -84,7 +84,7 @@ void EventRecorder::StopRecording() {
::timeEndPeriod(1);

DCHECK(file_ != NULL);
CloseFile(file_);
file_util::CloseFile(file_);
file_ = NULL;

journal_hook_ = NULL;
Expand All @@ -100,15 +100,15 @@ bool EventRecorder::StartPlayback(const FilePath& filename) {

// Open the recording file.
DCHECK(!file_);
file_ = OpenFile(filename, "rb");
file_ = file_util::OpenFile(filename, "rb");
if (!file_) {
DLOG(ERROR) << "EventRecorder Playback could not open log file";
return false;
}
// Read the first event from the record.
if (fread(&playback_msg_, sizeof(EVENTMSG), 1, file_) != 1) {
DLOG(ERROR) << "EventRecorder Playback has no records!";
CloseFile(file_);
file_util::CloseFile(file_);
return false;
}

Expand Down Expand Up @@ -150,7 +150,7 @@ void EventRecorder::StopPlayback() {
}

DCHECK(file_ != NULL);
CloseFile(file_);
file_util::CloseFile(file_);
file_ = NULL;

::timeEndPeriod(1);
Expand Down
23 changes: 12 additions & 11 deletions base/file_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ bool TextContentsEqual(const FilePath& filename1, const FilePath& filename2) {
bool ReadFileToString(const FilePath& path, std::string* contents) {
if (path.ReferencesParent())
return false;
FILE* file = OpenFile(path, "rb");
FILE* file = file_util::OpenFile(path, "rb");
if (!file) {
return false;
}
Expand All @@ -140,7 +140,7 @@ bool ReadFileToString(const FilePath& path, std::string* contents) {
if (contents)
contents->append(buf, len);
}
CloseFile(file);
file_util::CloseFile(file);

return true;
}
Expand Down Expand Up @@ -194,6 +194,16 @@ bool TouchFile(const FilePath& path,
return false;
}

} // namespace base

// -----------------------------------------------------------------------------

namespace file_util {

using base::FileEnumerator;
using base::FilePath;
using base::kMaxUniqueFiles;

bool CloseFile(FILE* file) {
if (file == NULL)
return true;
Expand All @@ -218,15 +228,6 @@ bool TruncateFile(FILE* file) {
return true;
}

} // namespace base

// -----------------------------------------------------------------------------

namespace file_util {

using base::FilePath;
using base::kMaxUniqueFiles;

int GetUniquePathNumber(
const FilePath& path,
const FilePath::StringType& suffix) {
Expand Down
19 changes: 12 additions & 7 deletions base/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,19 @@ BASE_EXPORT bool TouchFile(const FilePath& path,
const Time& last_accessed,
const Time& last_modified);

} // namespace base

// -----------------------------------------------------------------------------

namespace file_util {

#if defined(OS_POSIX)
// Store inode number of |path| in |inode|. Return true on success.
BASE_EXPORT bool GetInode(const base::FilePath& path, ino_t* inode);
#endif

// Wrapper for fopen-like calls. Returns non-NULL FILE* on success.
BASE_EXPORT FILE* OpenFile(const FilePath& filename, const char* mode);
BASE_EXPORT FILE* OpenFile(const base::FilePath& filename, const char* mode);

// Closes file opened by OpenFile. Returns true on success.
BASE_EXPORT bool CloseFile(FILE* file);
Expand All @@ -313,12 +324,6 @@ BASE_EXPORT bool TruncateFile(FILE* file);
// the number of read bytes, or -1 on error.
BASE_EXPORT int ReadFile(const base::FilePath& filename, char* data, int size);

} // namespace base

// -----------------------------------------------------------------------------

namespace file_util {

// Writes the given buffer into the file, overwriting any data that was
// previously there. Returns the number of bytes written, or -1 on error.
BASE_EXPORT int WriteFile(const base::FilePath& filename, const char* data,
Expand Down
53 changes: 32 additions & 21 deletions base/file_util_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -689,27 +689,6 @@ bool GetFileInfo(const FilePath& file_path, PlatformFileInfo* results) {
return true;
}

FILE* OpenFile(const FilePath& filename, const char* mode) {
ThreadRestrictions::AssertIOAllowed();
FILE* result = NULL;
do {
result = fopen(filename.value().c_str(), mode);
} while (!result && errno == EINTR);
return result;
}

int ReadFile(const FilePath& filename, char* data, int size) {
ThreadRestrictions::AssertIOAllowed();
int fd = HANDLE_EINTR(open(filename.value().c_str(), O_RDONLY));
if (fd < 0)
return -1;

ssize_t bytes_read = HANDLE_EINTR(read(fd, data, size));
if (int ret = IGNORE_EINTR(close(fd)) < 0)
return ret;
return bytes_read;
}

} // namespace base

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -744,10 +723,42 @@ base::FilePath MakeUniqueDirectory(const base::FilePath& path) {
return base::FilePath();
}

bool GetInode(const FilePath& path, ino_t* inode) {
base::ThreadRestrictions::AssertIOAllowed(); // For call to stat().
struct stat buffer;
int result = stat(path.value().c_str(), &buffer);
if (result < 0)
return false;

*inode = buffer.st_ino;
return true;
}

FILE* OpenFile(const std::string& filename, const char* mode) {
return OpenFile(FilePath(filename), mode);
}

FILE* OpenFile(const FilePath& filename, const char* mode) {
base::ThreadRestrictions::AssertIOAllowed();
FILE* result = NULL;
do {
result = fopen(filename.value().c_str(), mode);
} while (!result && errno == EINTR);
return result;
}

int ReadFile(const FilePath& filename, char* data, int size) {
base::ThreadRestrictions::AssertIOAllowed();
int fd = HANDLE_EINTR(open(filename.value().c_str(), O_RDONLY));
if (fd < 0)
return -1;

ssize_t bytes_read = HANDLE_EINTR(read(fd, data, size));
if (int ret = IGNORE_EINTR(close(fd)) < 0)
return ret;
return bytes_read;
}

int WriteFile(const FilePath& filename, const char* data, int size) {
base::ThreadRestrictions::AssertIOAllowed();
int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0666));
Expand Down
Loading

0 comments on commit a4f7378

Please sign in to comment.