1 // Copyright 2024 The Chromium Authors 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 BASE_TEST_FILE_PATH_REPARSE_POINT_WIN_H_ 6 #define BASE_TEST_FILE_PATH_REPARSE_POINT_WIN_H_ 7 8 #include <optional> 9 #include "base/files/file_path.h" 10 #include "base/win/scoped_handle.h" 11 12 namespace base::test { 13 14 // Manages a reparse point for a test. 15 class FilePathReparsePoint { 16 public: 17 // Creates a reparse point from |source| (an empty directory) to |target|. 18 static std::optional<FilePathReparsePoint> Create(const FilePath& source, 19 const FilePath& target); 20 FilePathReparsePoint(const FilePathReparsePoint&) = delete; 21 FilePathReparsePoint& operator=(const FilePathReparsePoint&) = delete; 22 23 // Move operations. 24 FilePathReparsePoint(FilePathReparsePoint&& other); 25 FilePathReparsePoint& operator=(FilePathReparsePoint&& other); 26 27 ~FilePathReparsePoint(); 28 29 private: 30 FilePathReparsePoint(const FilePath& source, const FilePath& target); IsValid()31 bool IsValid() const { return created_; } 32 bool SetReparsePoint(HANDLE source, const FilePath& target_path); 33 bool DeleteReparsePoint(HANDLE source); 34 35 win::ScopedHandle dir_; 36 bool created_; 37 }; 38 39 } // namespace base::test 40 41 #endif // BASE_TEST_FILE_PATH_REPARSE_POINT_WIN_H_ 42