LCOV - code coverage report
Current view: top level - src - filesys.h (source / functions) Hit Total Coverage
Test: report Lines: 1 1 100.0 %
Date: 2015-07-11 18:23:49 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /*
       2             : Minetest
       3             : Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
       4             : 
       5             : This program is free software; you can redistribute it and/or modify
       6             : it under the terms of the GNU Lesser General Public License as published by
       7             : the Free Software Foundation; either version 2.1 of the License, or
       8             : (at your option) any later version.
       9             : 
      10             : This program is distributed in the hope that it will be useful,
      11             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             : GNU Lesser General Public License for more details.
      14             : 
      15             : You should have received a copy of the GNU Lesser General Public License along
      16             : with this program; if not, write to the Free Software Foundation, Inc.,
      17             : 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             : */
      19             : 
      20             : #ifndef FILESYS_HEADER
      21             : #define FILESYS_HEADER
      22             : 
      23             : #include <string>
      24             : #include <vector>
      25             : #include "exceptions.h"
      26             : 
      27             : #ifdef _WIN32 // WINDOWS
      28             : #define DIR_DELIM "\\"
      29             : #define DIR_DELIM_CHAR '\\'
      30             : #define FILESYS_CASE_INSENSITIVE 1
      31             : #else // POSIX
      32             : #define DIR_DELIM "/"
      33             : #define DIR_DELIM_CHAR '/'
      34             : #define FILESYS_CASE_INSENSITIVE 0
      35             : #endif
      36             : 
      37             : namespace fs
      38             : {
      39             : 
      40          20 : struct DirListNode
      41             : {
      42             :         std::string name;
      43             :         bool dir;
      44             : };
      45             : 
      46             : std::vector<DirListNode> GetDirListing(const std::string &path);
      47             : 
      48             : // Returns true if already exists
      49             : bool CreateDir(const std::string &path);
      50             : 
      51             : bool PathExists(const std::string &path);
      52             : 
      53             : bool IsPathAbsolute(const std::string &path);
      54             : 
      55             : bool IsDir(const std::string &path);
      56             : 
      57             : bool IsDirDelimiter(char c);
      58             : 
      59             : // Only pass full paths to this one. True on success.
      60             : // NOTE: The WIN32 version returns always true.
      61             : bool RecursiveDelete(const std::string &path);
      62             : 
      63             : bool DeleteSingleFileOrEmptyDirectory(const std::string &path);
      64             : 
      65             : // Returns path to temp directory, can return "" on error
      66             : std::string TempPath();
      67             : 
      68             : /* Multiplatform */
      69             : 
      70             : // The path itself not included
      71             : void GetRecursiveSubPaths(const std::string &path, std::vector<std::string> &dst);
      72             : 
      73             : // Tries to delete all, returns false if any failed
      74             : bool DeletePaths(const std::vector<std::string> &paths);
      75             : 
      76             : // Only pass full paths to this one. True on success.
      77             : bool RecursiveDeleteContent(const std::string &path);
      78             : 
      79             : // Create all directories on the given path that don't already exist.
      80             : bool CreateAllDirs(const std::string &path);
      81             : 
      82             : // Copy a regular file
      83             : bool CopyFileContents(const std::string &source, const std::string &target);
      84             : 
      85             : // Copy directory and all subdirectories
      86             : // Omits files and subdirectories that start with a period
      87             : bool CopyDir(const std::string &source, const std::string &target);
      88             : 
      89             : // Check if one path is prefix of another
      90             : // For example, "/tmp" is a prefix of "/tmp" and "/tmp/file" but not "/tmp2"
      91             : // Ignores case differences and '/' vs. '\\' on Windows
      92             : bool PathStartsWith(const std::string &path, const std::string &prefix);
      93             : 
      94             : // Remove last path component and the dir delimiter before and/or after it,
      95             : // returns "" if there is only one path component.
      96             : // removed: If non-NULL, receives the removed component(s).
      97             : // count: Number of components to remove
      98             : std::string RemoveLastPathComponent(const std::string &path,
      99             :                std::string *removed = NULL, int count = 1);
     100             : 
     101             : // Remove "." and ".." path components and for every ".." removed, remove
     102             : // the last normal path component before it. Unlike AbsolutePath,
     103             : // this does not resolve symlinks and check for existence of directories.
     104             : std::string RemoveRelativePathComponents(std::string path);
     105             : 
     106             : // Returns the absolute path for the passed path, with "." and ".." path
     107             : // components and symlinks removed.  Returns "" on error.
     108             : std::string AbsolutePath(const std::string &path);
     109             : 
     110             : // Returns the filename from a path or the entire path if no directory
     111             : // delimiter is found.
     112             : const char *GetFilenameFromPath(const char *path);
     113             : 
     114             : bool safeWriteToFile(const std::string &path, const std::string &content);
     115             : 
     116             : } // namespace fs
     117             : 
     118             : #endif
     119             : 

Generated by: LCOV version 1.11