diff options
author | Laszlo Csomor <laszlocsomor@google.com> | 2017-02-14 10:16:23 +0000 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2017-02-14 14:23:52 +0000 |
commit | 5efe4a116027ae45edd4b8b5eb6ba58670b77f0f (patch) | |
tree | 8cd1b2bc5ea2afd799512fb00ab2e9549ba20c1e /src/main/native | |
parent | 015e5954157a6c071b6118b3d9b9f51676ccc6f3 (diff) |
Windows JNI, refactor: move OpenDirectory to JNI
Move the OpenDirectory helper method into the JNI
library. We'll need it there; a subsequent change
will make use of it there.
See https://github.com/bazelbuild/bazel/issues/2107
--
PiperOrigin-RevId: 147448792
MOS_MIGRATED_REVID=147448792
Diffstat (limited to 'src/main/native')
-rw-r--r-- | src/main/native/BUILD | 10 | ||||
-rw-r--r-- | src/main/native/windows_file_operations.cc | 13 | ||||
-rw-r--r-- | src/main/native/windows_file_operations.h | 8 |
3 files changed, 28 insertions, 3 deletions
diff --git a/src/main/native/BUILD b/src/main/native/BUILD index ba605707c1..653b595ad2 100644 --- a/src/main/native/BUILD +++ b/src/main/native/BUILD @@ -64,8 +64,14 @@ cc_binary( cc_library( name = "windows_jni_lib", - srcs = ["windows_util.cc"], - hdrs = ["windows_util.h"], + srcs = [ + "windows_file_operations.cc", + "windows_util.cc", + ], + hdrs = [ + "windows_file_operations.h", + "windows_util.h", + ], visibility = [ "//src/main/cpp:__subpackages__", "//src/test/cpp:__subpackages__", diff --git a/src/main/native/windows_file_operations.cc b/src/main/native/windows_file_operations.cc index e9e561eeb8..b5780b2c86 100644 --- a/src/main/native/windows_file_operations.cc +++ b/src/main/native/windows_file_operations.cc @@ -47,4 +47,17 @@ bool GetLongPath(const WCHAR* path, unique_ptr<WCHAR[]>* result) { return true; } +HANDLE OpenDirectory(const WCHAR* path, bool read_write) { + return ::CreateFileW( + /* lpFileName */ path, + /* dwDesiredAccess */ + read_write ? (GENERIC_READ | GENERIC_WRITE) : GENERIC_READ, + /* dwShareMode */ 0, + /* lpSecurityAttributes */ NULL, + /* dwCreationDisposition */ OPEN_EXISTING, + /* dwFlagsAndAttributes */ FILE_FLAG_OPEN_REPARSE_POINT | + FILE_FLAG_BACKUP_SEMANTICS, + /* hTemplateFile */ NULL); +} + } // namespace windows_util diff --git a/src/main/native/windows_file_operations.h b/src/main/native/windows_file_operations.h index e28200f359..ded07b0a1f 100644 --- a/src/main/native/windows_file_operations.h +++ b/src/main/native/windows_file_operations.h @@ -50,11 +50,17 @@ int IsJunctionOrDirectorySymlink(const WCHAR* path); // Computes the long version of `path` if it has any 8dot3 style components. // Returns true upon success and sets `result` to point to the buffer. // `path` must be an absolute, normalized, Windows style path, with a "\\?\" -// prefix if its longer than MAX_PATH. The result will have a "\\?\" prefix if +// prefix if it's longer than MAX_PATH. The result will have a "\\?\" prefix if // and only if `path` had one as well. (It's the caller's responsibility to keep // or remove this prefix.) bool GetLongPath(const WCHAR* path, unique_ptr<WCHAR[]>* result); +// Opens a directory using CreateFileW. +// `path` must be a valid Windows path, with "\\?\" prefix if it's long. +// If `read_write` is true then the directory is opened for reading and writing, +// otherwise only for reading. +HANDLE OpenDirectory(const WCHAR* path, bool read_write); + } // namespace windows_util #endif // BAZEL_SRC_MAIN_NATIVE_WINDOWS_FILE_OPERATIONS_H_ |