1/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_TSL_PLATFORM_FILE_SYSTEM_HELPER_H_
17#define TENSORFLOW_TSL_PLATFORM_FILE_SYSTEM_HELPER_H_
18
19#include <string>
20#include <vector>
21
22#include "tensorflow/tsl/platform/env.h"
23#include "tensorflow/tsl/platform/status.h"
24#include "tensorflow/tsl/platform/statusor.h"
25
26namespace tsl {
27
28class FileSystem;
29class Env;
30
31namespace internal {
32
33// Given a pattern, stores in 'results' the set of paths (in the given file
34// system) that match that pattern.
35//
36// This helper may be used by implementations of FileSystem::GetMatchingPaths()
37// in order to provide parallel scanning of subdirectories (except on iOS).
38//
39// Arguments:
40// fs: may not be null and will be used to identify directories and list
41// their contents.
42// env: may not be null and will be used to check if a match has been found.
43// pattern: see FileSystem::GetMatchingPaths() for details.
44// results: will be cleared and may not be null.
45//
46// Returns an error status if any call to 'fs' failed.
47Status GetMatchingPaths(FileSystem* fs, Env* env, const string& pattern,
48 std::vector<string>* results);
49
50// Given a file path, determines whether the file exists. This helper simplifies
51// the use of Env::FileExists.
52//
53// Arguments:
54// env: may not be null.
55// fname: the file path to look up
56//
57// Returns true if the file exists, false if it does not exist, or an error
58// Status.
59StatusOr<bool> FileExists(Env* env, const string& fname);
60
61} // namespace internal
62} // namespace tsl
63
64#endif // TENSORFLOW_TSL_PLATFORM_FILE_SYSTEM_HELPER_H_
65