test_file_util_linux.cc 665 Bytes
Newer Older
gejun's avatar
gejun committed
1 2 3 4 5 6 7 8 9
// 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.

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

10 11
#include "butil/files/file_path.h"
#include "butil/files/scoped_file.h"
gejun's avatar
gejun committed
12

13
namespace butil {
gejun's avatar
gejun committed
14 15 16 17 18 19 20 21 22 23 24 25

bool EvictFileFromSystemCache(const FilePath& file) {
  ScopedFD fd(open(file.value().c_str(), O_RDONLY));
  if (!fd.is_valid())
    return false;
  if (fdatasync(fd.get()) != 0)
    return false;
  if (posix_fadvise(fd.get(), 0, 0, POSIX_FADV_DONTNEED) != 0)
    return false;
  return true;
}

26
}  // namespace butil