test_file_util_linux.cc 665 B

1234567891011121314151617181920212223242526
  1. // Copyright (c) 2011 The Chromium 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.
  4. #include <fcntl.h>
  5. #include <sys/stat.h>
  6. #include <sys/types.h>
  7. #include <unistd.h>
  8. #include "butil/files/file_path.h"
  9. #include "butil/files/scoped_file.h"
  10. namespace butil {
  11. bool EvictFileFromSystemCache(const FilePath& file) {
  12. ScopedFD fd(open(file.value().c_str(), O_RDONLY));
  13. if (!fd.is_valid())
  14. return false;
  15. if (fdatasync(fd.get()) != 0)
  16. return false;
  17. if (posix_fadvise(fd.get(), 0, 0, POSIX_FADV_DONTNEED) != 0)
  18. return false;
  19. return true;
  20. }
  21. } // namespace butil