aboutsummaryrefslogtreecommitdiff
path: root/butl/filesystem
blob: 18ba48ea27314b0eec6a10fb0a59d632faf02580 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// file      : butl/filesystem -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BUTL_FILESYSTEM
#define BUTL_FILESYSTEM

#include <sys/types.h> // mode_t

#include <butl/path>
#include <butl/timestamp>

namespace butl
{
  // Return timestamp_nonexistent if the entry at the specified path
  // does not exist or is not a path. All other errors are reported
  // by throwing std::system_error. Note that this function resolves
  // symlinks.
  //
  timestamp
  file_mtime (const path&);

  // Return true if the path is to an existing directory. Note that
  // this function resolves symlinks.
  //
  bool
  dir_exists (const path&);

  // Return true if the path is to an existing regular file. Note that
  // this function resolves symlinks.
  //
  bool
  file_exists (const path&);

  // Try to create a directory unless it already exists. If you expect
  // the directory to exist and performance is important, then you
  // should first call dir_exists() above since that's what this
  // implementation will do to make sure the path is actually a
  // directory.
  //
  // You should also probably use the default mode 0777 and let the
  // umask mechanism adjust it to the user's preferences.
  //
  // Errors are reported by throwing std::system_error.
  //
  enum class mkdir_status {success, already_exists};

  mkdir_status
  try_mkdir (const path&, mode_t = 0777);

  // Try to remove the directory returning not_exist if it does not
  // exist and not_empty if it is not empty. All other errors are
  // reported by throwing std::system_error.
  //
  enum class rmdir_status {success, not_exist, not_empty};

  rmdir_status
  try_rmdir (const path&);

  // Try to remove the file (or symlinks) returning not_exist if
  // it does not exist. All other errors are reported by throwing
  // std::system_error.
  //
  enum class rmfile_status {success, not_exist};

  rmfile_status
  try_rmfile (const path&);
}

#endif // BUTL_FILESYSTEM