1// Copyright 2014 The Chromium OS 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 5#ifndef LIBBRILLO_BRILLO_FILE_UTILS_H_ 6#define LIBBRILLO_BRILLO_FILE_UTILS_H_ 7 8#include <sys/types.h> 9 10#include <base/files/file_path.h> 11#include <brillo/brillo_export.h> 12 13namespace brillo { 14 15// Ensures a regular file owned by user |uid| and group |gid| exists at |path|. 16// Any other entity at |path| will be deleted and replaced with an empty 17// regular file. If a new file is needed, any missing parent directories will 18// be created, and the file will be assigned |new_file_permissions|. 19// Should be safe to use in all directories, including tmpdirs with the sticky 20// bit set. 21// Returns true if the file existed or was able to be created. 22BRILLO_EXPORT bool TouchFile(const base::FilePath& path, 23 int new_file_permissions, 24 uid_t uid, 25 gid_t gid); 26 27// Convenience version of TouchFile() defaulting to 600 permissions and the 28// current euid/egid. 29// Should be safe to use in all directories, including tmpdirs with the sticky 30// bit set. 31BRILLO_EXPORT bool TouchFile(const base::FilePath& path); 32 33} // namespace brillo 34 35#endif // LIBBRILLO_BRILLO_FILE_UTILS_H_ 36