Turi Create  4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fs_util.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_FS_UTIL
7 #define TURI_FS_UTIL
8 
9 #include <string>
10 #include <vector>
11 
12 
13 namespace turi {
14 
15  namespace fs_util {
16 
17  /**
18  * Attempts to increase the file handle limit.
19  * Returns true on success, false on failure.
20  */
21  bool upgrade_file_handle_limit(size_t limit);
22 
23  /**
24  * Gets the current file handle limit.
25  * Returns the current file handle limit on success,
26  * -1 on infinity, and 0 on failure.
27  */
28  int get_file_handle_limit();
29 
30  /**
31  * List all the files with the given suffix at the pathname
32  * location
33  */
34  void list_files_with_suffix(const std::string& pathname,
35  const std::string& suffix,
36  std::vector<std::string>& files,
37  bool ignore_hidden = true);
38 
39  /**
40  * List all the files with the given prefix at the pathname
41  * location
42  */
43  void list_files_with_prefix(const std::string& pathname,
44  const std::string& prefix,
45  std::vector<std::string>& files,
46  bool ignore_hidden = true);
47 
48  /// \ingroup util_internal
49  std::string change_suffix(const std::string& fname,
50  const std::string& new_suffix);
51 
52  std::string join(const std::vector<std::string>& components);
53 
54  // Generate a path under the system temporary directory.
55  // NOTE: This function (like the underlying boost::filesystem call) does
56  // not guard against race conditions, and therefore should not be used in
57  // security-critical settings.
58  std::string system_temp_directory_unique_path(const std::string& prefix,
59  const std::string& suffix);
60 
61  }; // end of fs_utils
62 
63 
64 }; // end of turicreate
65 #endif