Skip to content

Commit

Permalink
In test_file_util_mac.cc, when evicting file from cache, do not map a…
Browse files Browse the repository at this point in the history
… file when it is empty.

BUG=none
TEST=none


Review URL: http://codereview.chromium.org/7484052

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95334 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hnguyen@chromium.org committed Aug 3, 2011
1 parent d912daa commit 93f4783
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions base/test/test_file_util_mac.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -17,15 +17,28 @@ bool EvictFileFromSystemCache(const FilePath& file) {
// default) + MAP_SHARED, then do an msync to invalidate the memory. The next
// open should then have to load the file from disk.

int64 length;
if (!file_util::GetFileSize(file, &length)) {
LOG(ERROR) << "failed to get size of " << file.value();
return false;
}

// When a file is empty, we do not need to evict it from cache.
// In fact, an attempt to map it to memory will result in error.
if (length == 0) {
LOG(WARNING) << "file size is zero, will not attempt to map to memory";
return true;
}

file_util::MemoryMappedFile mapped_file;
if (!mapped_file.Initialize(file)) {
DLOG(WARNING) << "failed to memory map " << file.value();
LOG(WARNING) << "failed to memory map " << file.value();
return false;
}

if (msync(const_cast<uint8*>(mapped_file.data()), mapped_file.length(),
MS_INVALIDATE) != 0) {
DLOG(WARNING) << "failed to invalidate memory map of " << file.value()
LOG(WARNING) << "failed to invalidate memory map of " << file.value()
<< ", errno: " << errno;
return false;
}
Expand Down

0 comments on commit 93f4783

Please sign in to comment.