LCOV - code coverage report
Current view: top level - source/lib/file - file_system.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 12 12 100.0 %
Date: 2026-12-03 01:19:39 Functions: 0 0 -

          Line data    Source code
       1             : /* Copyright (C) 2026 Wildfire Games.
       2             :  *
       3             :  * Permission is hereby granted, free of charge, to any person obtaining
       4             :  * a copy of this software and associated documentation files (the
       5             :  * "Software"), to deal in the Software without restriction, including
       6             :  * without limitation the rights to use, copy, modify, merge, publish,
       7             :  * distribute, sublicense, and/or sell copies of the Software, and to
       8             :  * permit persons to whom the Software is furnished to do so, subject to
       9             :  * the following conditions:
      10             :  *
      11             :  * The above copyright notice and this permission notice shall be included
      12             :  * in all copies or substantial portions of the Software.
      13             :  *
      14             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      15             :  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      16             :  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      17             :  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
      18             :  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
      19             :  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      20             :  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      21             :  */
      22             : 
      23             : /*
      24             :  * higher-level interface on top of sysdep/filesystem.h
      25             :  */
      26             : 
      27             : #ifndef INCLUDED_FILE_SYSTEM
      28             : #define INCLUDED_FILE_SYSTEM
      29             : 
      30             : #include "lib/os_path.h"
      31             : #include "lib/posix/posix_filesystem.h"
      32             : #include "lib/posix/posix_types.h"
      33             : #include "lib/status.h"
      34             : 
      35             : #include <vector>
      36             : 
      37             : bool DirectoryExists(const OsPath& path);
      38             : 
      39             : // (bundling size and mtime avoids a second expensive call to stat())
      40      115664 : class CFileInfo
      41             : {
      42             : public:
      43        8892 :     CFileInfo()
      44        8892 :     {
      45          15 :     }
      46             : 
      47       33987 :     CFileInfo(const OsPath& name, off_t size, time_t mtime)
      48       33987 :         : name(name), size(size), mtime(mtime)
      49             :     {
      50             :     }
      51             : 
      52       36950 :     const OsPath& Name() const
      53             :     {
      54       49011 :         return name;
      55             :     }
      56             : 
      57       20767 :     off_t Size() const
      58             :     {
      59       20767 :         return size;
      60             :     }
      61             : 
      62       20767 :     time_t MTime() const
      63             :     {
      64       20767 :         return mtime;
      65             :     }
      66             : 
      67             : private:
      68             :     OsPath name;
      69             :     off_t size;
      70             :     time_t mtime;
      71             : };
      72             : 
      73             : Status GetFileInfo(const OsPath& pathname, CFileInfo* fileInfo);
      74             : 
      75             : typedef std::vector<CFileInfo> CFileInfos;
      76             : typedef std::vector<OsPath> DirectoryNames;
      77             : 
      78             : Status GetDirectoryEntries(const OsPath& path, CFileInfos* files, DirectoryNames* subdirectoryNames);
      79             : 
      80             : // same as boost::filesystem::create_directories, except that mkdir is invoked with
      81             : // <mode> instead of 0755.
      82             : // If the breakpoint is enabled, debug_break will be called if the directory didn't exist and couldn't be created.
      83             : Status CreateDirectories(const OsPath& path, mode_t mode, bool breakpoint = true);
      84             : 
      85             : Status DeleteDirectory(const OsPath& dirPath);
      86             : 
      87             : Status CopyFile(const OsPath& path, const OsPath& newPath, bool override_if_exists = false);
      88             : 
      89             : Status RenameFile(const OsPath& path, const OsPath& newPath);
      90             : 
      91             : #endif  // #ifndef INCLUDED_FILE_SYSTEM

Generated by: LCOV version 1.16