2018-04-26 23:47:01 +03:00
|
|
|
#!/usr/bin/env python3
|
2019-06-20 02:58:25 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
2018-04-26 23:47:01 +03:00
|
|
|
#
|
2019-06-20 02:58:25 +03:00
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2.
|
2018-04-26 23:47:01 +03:00
|
|
|
|
2021-01-27 23:02:25 +03:00
|
|
|
import logging
|
|
|
|
from typing import List, Optional, Tuple
|
2018-05-10 07:33:49 +03:00
|
|
|
|
2019-10-29 19:20:57 +03:00
|
|
|
from facebook.eden.ttypes import EdenError, EdenErrorType, GlobParams
|
2018-05-10 07:33:49 +03:00
|
|
|
|
2018-04-26 23:47:01 +03:00
|
|
|
from .lib import testcase
|
|
|
|
|
|
|
|
|
|
|
|
@testcase.eden_repo_test
|
|
|
|
class GlobTest(testcase.EdenRepoTest):
|
|
|
|
def populate_repo(self) -> None:
|
2020-10-29 23:31:37 +03:00
|
|
|
self.repo.write_file("hello", "bonjour\n")
|
|
|
|
self.repo.write_file("hola", "hello\n")
|
|
|
|
self.repo.write_file("adir/phile", "phoo!\n")
|
|
|
|
|
|
|
|
self.commit0 = self.repo.commit("Commit 0.")
|
|
|
|
|
|
|
|
self.repo.remove_files(["hello", "hola", "adir/phile"])
|
2018-05-10 07:33:49 +03:00
|
|
|
self.repo.write_file("hello", "hola\n")
|
|
|
|
self.repo.write_file("adir/file", "foo!\n")
|
|
|
|
self.repo.write_file("bdir/file", "bar!\n")
|
|
|
|
self.repo.write_file("bdir/otherfile", "foo!\n")
|
|
|
|
self.repo.symlink("slink", "hello")
|
|
|
|
self.repo.write_file("cdir/subdir/new.txt", "and improved")
|
|
|
|
self.repo.write_file("ddir/notdotfile", "")
|
|
|
|
self.repo.write_file("ddir/subdir/notdotfile", "")
|
|
|
|
self.repo.write_file("ddir/subdir/.dotfile", "")
|
|
|
|
|
|
|
|
self.repo.write_file("java/com/example/package.html", "")
|
|
|
|
self.repo.write_file("java/com/example/Example.java", "")
|
|
|
|
self.repo.write_file("java/com/example/foo/Foo.java", "")
|
|
|
|
self.repo.write_file("java/com/example/foo/bar/Bar.java", "")
|
|
|
|
self.repo.write_file("java/com/example/foo/bar/baz/Baz.java", "")
|
|
|
|
|
2021-02-24 06:56:18 +03:00
|
|
|
self.repo.write_file("other/exclude.java", "")
|
|
|
|
|
2020-10-29 23:31:37 +03:00
|
|
|
self.commit1 = self.repo.commit("Commit 1.")
|
2018-04-26 23:47:01 +03:00
|
|
|
|
|
|
|
def setUp(self) -> None:
|
2020-10-29 23:31:37 +03:00
|
|
|
# needs to be done before set up because these need to be created
|
|
|
|
# for populate_repo() and the supers set up will call this.
|
|
|
|
self.commit0 = ""
|
|
|
|
self.commit1 = ""
|
|
|
|
|
2018-04-26 23:47:01 +03:00
|
|
|
super().setUp()
|
2020-10-29 23:31:37 +03:00
|
|
|
|
2018-04-26 23:47:01 +03:00
|
|
|
self.client = self.get_thrift_client()
|
|
|
|
self.client.open()
|
|
|
|
self.addCleanup(self.client.close)
|
|
|
|
|
2018-04-26 23:47:03 +03:00
|
|
|
def test_exact_path_component_match(self) -> None:
|
2021-02-24 06:56:18 +03:00
|
|
|
self.assert_glob(["hello"], [b"hello"])
|
|
|
|
self.assert_glob(["ddir/subdir/.dotfile"], [b"ddir/subdir/.dotfile"])
|
2018-04-26 23:47:03 +03:00
|
|
|
|
|
|
|
def test_wildcard_path_component_match(self) -> None:
|
2021-02-24 06:56:18 +03:00
|
|
|
self.assert_glob(["hel*"], [b"hello"])
|
|
|
|
self.assert_glob(["ad*"], [b"adir"])
|
|
|
|
self.assert_glob_with_dtypes(["ad*"], [(b"adir", "d")])
|
|
|
|
self.assert_glob(["a*/file"], [b"adir/file"])
|
|
|
|
self.assert_glob_with_dtypes(["a*/file"], [(b"adir/file", "f")])
|
2018-04-26 23:47:03 +03:00
|
|
|
|
|
|
|
def test_no_accidental_substring_match(self) -> None:
|
2018-05-10 07:33:49 +03:00
|
|
|
self.assert_glob(["hell"], [], msg="No accidental substring match")
|
2018-04-26 23:47:03 +03:00
|
|
|
|
|
|
|
def test_match_all_files_in_directory(self) -> None:
|
2021-02-24 06:56:18 +03:00
|
|
|
self.assert_glob(["bdir/*"], [b"bdir/file", b"bdir/otherfile"])
|
2018-04-26 23:47:05 +03:00
|
|
|
|
|
|
|
def test_match_all_files_in_directory_with_dotfile(self) -> None:
|
2021-02-24 06:56:18 +03:00
|
|
|
self.assert_glob(["ddir/subdir/*"], [b"ddir/subdir/notdotfile"])
|
2018-04-26 23:47:03 +03:00
|
|
|
|
|
|
|
def test_overlapping_globs(self) -> None:
|
2018-04-26 23:47:07 +03:00
|
|
|
self.assert_glob(
|
2018-05-10 07:33:49 +03:00
|
|
|
["adir/*", "**/file"],
|
2021-02-24 06:56:18 +03:00
|
|
|
[b"adir/file", b"bdir/file"],
|
2018-05-10 07:33:49 +03:00
|
|
|
msg="De-duplicate results from multiple globs",
|
2018-04-26 23:47:01 +03:00
|
|
|
)
|
2018-04-26 23:47:03 +03:00
|
|
|
|
|
|
|
def test_recursive_wildcard_prefix(self) -> None:
|
2021-02-24 06:56:18 +03:00
|
|
|
self.assert_glob(["**/file"], [b"adir/file", b"bdir/file"])
|
2018-04-26 23:47:03 +03:00
|
|
|
|
|
|
|
def test_recursive_wildcard_suffix(self) -> None:
|
2021-02-24 06:56:18 +03:00
|
|
|
self.assert_glob(["adir/**"], [b"adir/file"])
|
|
|
|
self.assert_glob(["adir/**/*"], [b"adir/file"])
|
2018-04-26 23:47:01 +03:00
|
|
|
|
2018-04-26 23:47:05 +03:00
|
|
|
def test_recursive_wildcard_suffix_with_dotfile(self) -> None:
|
2018-04-26 23:47:07 +03:00
|
|
|
self.assert_glob(
|
2021-02-24 06:56:18 +03:00
|
|
|
["ddir/**"], [b"ddir/notdotfile", b"ddir/subdir", b"ddir/subdir/notdotfile"]
|
2018-04-26 23:47:05 +03:00
|
|
|
)
|
2018-04-26 23:47:07 +03:00
|
|
|
self.assert_glob(
|
2018-05-10 07:33:49 +03:00
|
|
|
["ddir/**"],
|
|
|
|
[
|
2021-02-24 06:56:18 +03:00
|
|
|
b"ddir/notdotfile",
|
|
|
|
b"ddir/subdir",
|
|
|
|
b"ddir/subdir/.dotfile",
|
|
|
|
b"ddir/subdir/notdotfile",
|
Thrift API change: deprecate glob() in favor of globFiles().
Summary:
We need to introduce a new `includeDotfiles` option to `glob()`. [As we have
done for all of our Thrift API, to date], rather than define `glob()` so that it
takes a single struct, we specified the parameters individually, so we can no
longer add new params to `glob()`.
In particular, we need to support `includeDotfiles` because we often configure
Buck to use Watchman to implement `glob()` in `BUCK` files, and when Watchman is
used in Eden, it leverages Eden's Thrift API to implement `glob()`. Because
Buck's `glob()` has an `include_dotfiles` option, we must be able to honor it
and pass it all the way through to Eden's `glob()` implementation.
Rather than name the new API `glob2()`, I'm electing to go with `globFiles()`.
(Perhaps once we eliminate all known users of `glob()` in the wild, which
requires turning over the current version of Watchman we have deployed, we can
redefine `glob()` in `eden.thrift` to be the same as `globFiles()` and then
update everyone to use `glob()` again so it has the more intuitive name.)
Reviewed By: wez
Differential Revision: D7748870
fbshipit-source-id: 92438f9c41e4fbdbd6cdccca5fce0e41cc3e9b07
2018-05-03 00:41:34 +03:00
|
|
|
],
|
2018-05-10 07:33:49 +03:00
|
|
|
include_dotfiles=True,
|
Thrift API change: deprecate glob() in favor of globFiles().
Summary:
We need to introduce a new `includeDotfiles` option to `glob()`. [As we have
done for all of our Thrift API, to date], rather than define `glob()` so that it
takes a single struct, we specified the parameters individually, so we can no
longer add new params to `glob()`.
In particular, we need to support `includeDotfiles` because we often configure
Buck to use Watchman to implement `glob()` in `BUCK` files, and when Watchman is
used in Eden, it leverages Eden's Thrift API to implement `glob()`. Because
Buck's `glob()` has an `include_dotfiles` option, we must be able to honor it
and pass it all the way through to Eden's `glob()` implementation.
Rather than name the new API `glob2()`, I'm electing to go with `globFiles()`.
(Perhaps once we eliminate all known users of `glob()` in the wild, which
requires turning over the current version of Watchman we have deployed, we can
redefine `glob()` in `eden.thrift` to be the same as `globFiles()` and then
update everyone to use `glob()` again so it has the more intuitive name.)
Reviewed By: wez
Differential Revision: D7748870
fbshipit-source-id: 92438f9c41e4fbdbd6cdccca5fce0e41cc3e9b07
2018-05-03 00:41:34 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
self.assert_glob(
|
2021-02-24 06:56:18 +03:00
|
|
|
["ddir/**/*"],
|
|
|
|
[b"ddir/notdotfile", b"ddir/subdir", b"ddir/subdir/notdotfile"],
|
Thrift API change: deprecate glob() in favor of globFiles().
Summary:
We need to introduce a new `includeDotfiles` option to `glob()`. [As we have
done for all of our Thrift API, to date], rather than define `glob()` so that it
takes a single struct, we specified the parameters individually, so we can no
longer add new params to `glob()`.
In particular, we need to support `includeDotfiles` because we often configure
Buck to use Watchman to implement `glob()` in `BUCK` files, and when Watchman is
used in Eden, it leverages Eden's Thrift API to implement `glob()`. Because
Buck's `glob()` has an `include_dotfiles` option, we must be able to honor it
and pass it all the way through to Eden's `glob()` implementation.
Rather than name the new API `glob2()`, I'm electing to go with `globFiles()`.
(Perhaps once we eliminate all known users of `glob()` in the wild, which
requires turning over the current version of Watchman we have deployed, we can
redefine `glob()` in `eden.thrift` to be the same as `globFiles()` and then
update everyone to use `glob()` again so it has the more intuitive name.)
Reviewed By: wez
Differential Revision: D7748870
fbshipit-source-id: 92438f9c41e4fbdbd6cdccca5fce0e41cc3e9b07
2018-05-03 00:41:34 +03:00
|
|
|
)
|
|
|
|
self.assert_glob(
|
2018-05-10 07:33:49 +03:00
|
|
|
["ddir/**/*"],
|
|
|
|
[
|
2021-02-24 06:56:18 +03:00
|
|
|
b"ddir/notdotfile",
|
|
|
|
b"ddir/subdir",
|
|
|
|
b"ddir/subdir/.dotfile",
|
|
|
|
b"ddir/subdir/notdotfile",
|
Thrift API change: deprecate glob() in favor of globFiles().
Summary:
We need to introduce a new `includeDotfiles` option to `glob()`. [As we have
done for all of our Thrift API, to date], rather than define `glob()` so that it
takes a single struct, we specified the parameters individually, so we can no
longer add new params to `glob()`.
In particular, we need to support `includeDotfiles` because we often configure
Buck to use Watchman to implement `glob()` in `BUCK` files, and when Watchman is
used in Eden, it leverages Eden's Thrift API to implement `glob()`. Because
Buck's `glob()` has an `include_dotfiles` option, we must be able to honor it
and pass it all the way through to Eden's `glob()` implementation.
Rather than name the new API `glob2()`, I'm electing to go with `globFiles()`.
(Perhaps once we eliminate all known users of `glob()` in the wild, which
requires turning over the current version of Watchman we have deployed, we can
redefine `glob()` in `eden.thrift` to be the same as `globFiles()` and then
update everyone to use `glob()` again so it has the more intuitive name.)
Reviewed By: wez
Differential Revision: D7748870
fbshipit-source-id: 92438f9c41e4fbdbd6cdccca5fce0e41cc3e9b07
2018-05-03 00:41:34 +03:00
|
|
|
],
|
2018-05-10 07:33:49 +03:00
|
|
|
include_dotfiles=True,
|
2018-04-26 23:47:05 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_qualified_recursive_wildcard(self) -> None:
|
2018-04-26 23:47:07 +03:00
|
|
|
self.assert_glob(
|
2018-05-10 07:33:49 +03:00
|
|
|
["java/com/**/*.java"],
|
|
|
|
[
|
2021-02-24 06:56:18 +03:00
|
|
|
b"java/com/example/Example.java",
|
|
|
|
b"java/com/example/foo/Foo.java",
|
|
|
|
b"java/com/example/foo/bar/Bar.java",
|
|
|
|
b"java/com/example/foo/bar/baz/Baz.java",
|
2018-05-10 07:33:49 +03:00
|
|
|
],
|
2018-04-26 23:47:05 +03:00
|
|
|
)
|
2018-04-26 23:47:07 +03:00
|
|
|
self.assert_glob(
|
2021-02-24 06:56:18 +03:00
|
|
|
["java/com/example/*/*.java"], [b"java/com/example/foo/Foo.java"]
|
2018-04-26 23:47:05 +03:00
|
|
|
)
|
|
|
|
|
2018-04-26 23:47:03 +03:00
|
|
|
def test_malformed_query(self) -> None:
|
2018-04-26 23:47:01 +03:00
|
|
|
with self.assertRaises(EdenError) as ctx:
|
2020-12-02 00:37:58 +03:00
|
|
|
self.client.globFiles(
|
|
|
|
GlobParams(mountPoint=self.mount_path_bytes, globs=["adir["])
|
|
|
|
)
|
2018-05-10 07:33:49 +03:00
|
|
|
self.assertIn("unterminated bracket sequence", str(ctx.exception))
|
2019-10-29 19:20:57 +03:00
|
|
|
self.assertEqual(EdenErrorType.POSIX_ERROR, ctx.exception.errorType)
|
2018-04-26 23:47:07 +03:00
|
|
|
|
2018-07-13 21:14:54 +03:00
|
|
|
with self.assertRaises(EdenError) as ctx:
|
2018-08-11 11:34:44 +03:00
|
|
|
self.client.globFiles(GlobParams(self.mount_path_bytes, ["adir["], True))
|
2018-07-13 21:14:54 +03:00
|
|
|
self.assertIn("unterminated bracket sequence", str(ctx.exception))
|
2019-10-29 19:20:57 +03:00
|
|
|
self.assertEqual(EdenErrorType.POSIX_ERROR, ctx.exception.errorType)
|
2018-07-13 21:14:54 +03:00
|
|
|
|
2020-11-17 23:52:09 +03:00
|
|
|
def test_globs_may_not_include_dotdot(self):
|
|
|
|
with self.assertRaises(EdenError) as ctx:
|
|
|
|
self.client.globFiles(
|
|
|
|
GlobParams(self.mount_path_bytes, ["java/../java/com/**/*.java"])
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
"Invalid glob (PathComponent must not be ..): java/../java/com/**/*.java",
|
|
|
|
str(ctx.exception),
|
|
|
|
)
|
|
|
|
self.assertEqual(EdenErrorType.ARGUMENT_ERROR, ctx.exception.errorType)
|
|
|
|
|
2020-10-29 23:31:37 +03:00
|
|
|
def test_glob_on_non_current_commit(self) -> None:
|
2021-02-24 06:56:18 +03:00
|
|
|
self.assert_glob(["hello"], [b"hello"], commits=[bytes.fromhex(self.commit0)])
|
|
|
|
self.assert_glob(["hola"], [b"hola"], commits=[bytes.fromhex(self.commit0)])
|
2020-10-29 23:31:37 +03:00
|
|
|
|
|
|
|
def test_glob_multiple_commits(self) -> None:
|
|
|
|
self.assert_glob(
|
|
|
|
["hello"],
|
2021-02-24 06:56:18 +03:00
|
|
|
[b"hello", b"hello"],
|
2020-10-29 23:31:37 +03:00
|
|
|
commits=[bytes.fromhex(self.commit0), bytes.fromhex(self.commit1)],
|
|
|
|
)
|
|
|
|
self.assert_glob(
|
|
|
|
["h*"],
|
2021-02-24 06:56:18 +03:00
|
|
|
[b"hello", b"hello", b"hola"],
|
2020-10-29 23:31:37 +03:00
|
|
|
commits=[bytes.fromhex(self.commit0), bytes.fromhex(self.commit1)],
|
|
|
|
)
|
|
|
|
self.assert_glob(
|
|
|
|
["a*/*ile"],
|
2021-02-24 06:56:18 +03:00
|
|
|
[b"adir/file", b"adir/phile"],
|
2020-10-29 23:31:37 +03:00
|
|
|
commits=[bytes.fromhex(self.commit0), bytes.fromhex(self.commit1)],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_prefetch_matching_files(self) -> None:
|
2021-02-24 06:56:18 +03:00
|
|
|
self.assert_glob(["hello"], [b"hello"], prefetching=True)
|
2020-10-29 23:31:37 +03:00
|
|
|
self.assert_glob(
|
|
|
|
["hello"],
|
2021-02-24 06:56:18 +03:00
|
|
|
[b"hello"],
|
2020-10-29 23:31:37 +03:00
|
|
|
prefetching=True,
|
|
|
|
commits=[bytes.fromhex(self.commit0)],
|
|
|
|
)
|
|
|
|
self.assert_glob(
|
|
|
|
["hello"],
|
2021-02-24 06:56:18 +03:00
|
|
|
[b"hello", b"hello"],
|
2020-10-29 23:31:37 +03:00
|
|
|
prefetching=True,
|
|
|
|
commits=[bytes.fromhex(self.commit0), bytes.fromhex(self.commit1)],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_simple_matching_commit(self) -> None:
|
|
|
|
self.assert_glob(
|
|
|
|
["hello"],
|
2021-02-24 06:56:18 +03:00
|
|
|
expected_matches=[b"hello"],
|
2020-10-29 23:31:37 +03:00
|
|
|
expected_commits=[bytes.fromhex(self.commit1)],
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assert_glob(
|
|
|
|
["hello"],
|
2021-02-24 06:56:18 +03:00
|
|
|
expected_matches=[b"hello"],
|
2020-10-29 23:31:37 +03:00
|
|
|
expected_commits=[bytes.fromhex(self.commit0)],
|
|
|
|
commits=[bytes.fromhex(self.commit0)],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_duplicate_file_multiple_commits(self) -> None:
|
|
|
|
self.assert_glob(
|
|
|
|
["hello"],
|
2021-02-24 06:56:18 +03:00
|
|
|
expected_matches=[b"hello", b"hello"],
|
2020-10-29 23:31:37 +03:00
|
|
|
expected_commits=[
|
|
|
|
bytes.fromhex(self.commit0),
|
|
|
|
bytes.fromhex(self.commit1),
|
|
|
|
],
|
|
|
|
commits=[bytes.fromhex(self.commit0), bytes.fromhex(self.commit1)],
|
|
|
|
)
|
|
|
|
|
2021-02-24 06:56:18 +03:00
|
|
|
def test_multiple_file_multiple_commits(self) -> None:
|
|
|
|
self.assert_glob(
|
|
|
|
["a*/*ile"],
|
|
|
|
[b"adir/file", b"adir/phile"],
|
|
|
|
expected_commits=[
|
|
|
|
bytes.fromhex(self.commit1),
|
|
|
|
bytes.fromhex(self.commit0),
|
|
|
|
],
|
|
|
|
commits=[bytes.fromhex(self.commit0), bytes.fromhex(self.commit1)],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_search_root(self) -> None:
|
|
|
|
self.assert_glob(
|
|
|
|
["**/*.java"],
|
|
|
|
expected_matches=[
|
|
|
|
b"example/Example.java",
|
|
|
|
b"example/foo/Foo.java",
|
|
|
|
b"example/foo/bar/Bar.java",
|
|
|
|
b"example/foo/bar/baz/Baz.java",
|
|
|
|
],
|
|
|
|
search_root=b"java/com",
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_search_root_with_specified_commits(self) -> None:
|
|
|
|
self.assert_glob(
|
|
|
|
["**/*.java"],
|
|
|
|
expected_matches=[
|
|
|
|
b"example/Example.java",
|
|
|
|
b"example/foo/Foo.java",
|
|
|
|
b"example/foo/bar/Bar.java",
|
|
|
|
b"example/foo/bar/baz/Baz.java",
|
|
|
|
],
|
|
|
|
expected_commits=[
|
|
|
|
bytes.fromhex(self.commit1),
|
|
|
|
bytes.fromhex(self.commit1),
|
|
|
|
bytes.fromhex(self.commit1),
|
|
|
|
bytes.fromhex(self.commit1),
|
|
|
|
],
|
|
|
|
commits=[bytes.fromhex(self.commit1)],
|
|
|
|
search_root=b"java/com",
|
|
|
|
)
|
2020-10-29 23:31:37 +03:00
|
|
|
|
2018-04-26 23:47:07 +03:00
|
|
|
def assert_glob(
|
|
|
|
self,
|
|
|
|
globs: List[str],
|
2021-02-24 06:56:18 +03:00
|
|
|
expected_matches: List[bytes],
|
Thrift API change: deprecate glob() in favor of globFiles().
Summary:
We need to introduce a new `includeDotfiles` option to `glob()`. [As we have
done for all of our Thrift API, to date], rather than define `glob()` so that it
takes a single struct, we specified the parameters individually, so we can no
longer add new params to `glob()`.
In particular, we need to support `includeDotfiles` because we often configure
Buck to use Watchman to implement `glob()` in `BUCK` files, and when Watchman is
used in Eden, it leverages Eden's Thrift API to implement `glob()`. Because
Buck's `glob()` has an `include_dotfiles` option, we must be able to honor it
and pass it all the way through to Eden's `glob()` implementation.
Rather than name the new API `glob2()`, I'm electing to go with `globFiles()`.
(Perhaps once we eliminate all known users of `glob()` in the wild, which
requires turning over the current version of Watchman we have deployed, we can
redefine `glob()` in `eden.thrift` to be the same as `globFiles()` and then
update everyone to use `glob()` again so it has the more intuitive name.)
Reviewed By: wez
Differential Revision: D7748870
fbshipit-source-id: 92438f9c41e4fbdbd6cdccca5fce0e41cc3e9b07
2018-05-03 00:41:34 +03:00
|
|
|
include_dotfiles: bool = False,
|
2018-05-10 07:33:49 +03:00
|
|
|
msg: Optional[str] = None,
|
2020-10-29 23:31:37 +03:00
|
|
|
commits: Optional[List[bytes]] = None,
|
|
|
|
prefetching: bool = False,
|
|
|
|
expected_commits: Optional[List[bytes]] = None,
|
2021-02-24 06:56:18 +03:00
|
|
|
search_root: Optional[bytes] = None,
|
2018-04-26 23:47:07 +03:00
|
|
|
) -> None:
|
2020-10-29 23:31:37 +03:00
|
|
|
params = GlobParams(
|
|
|
|
mountPoint=self.mount_path_bytes,
|
|
|
|
globs=globs,
|
|
|
|
includeDotfiles=include_dotfiles,
|
|
|
|
prefetchFiles=prefetching,
|
|
|
|
revisions=commits,
|
2021-02-24 06:56:18 +03:00
|
|
|
searchRoot=search_root,
|
2020-10-29 23:31:37 +03:00
|
|
|
)
|
2021-01-27 23:02:25 +03:00
|
|
|
result = self.client.globFiles(params)
|
2021-02-24 06:56:18 +03:00
|
|
|
self.assertEqual(expected_matches, sorted(result.matchingFiles), msg=msg)
|
2021-01-27 23:02:25 +03:00
|
|
|
self.assertFalse(result.dtypes)
|
Thrift API change: deprecate glob() in favor of globFiles().
Summary:
We need to introduce a new `includeDotfiles` option to `glob()`. [As we have
done for all of our Thrift API, to date], rather than define `glob()` so that it
takes a single struct, we specified the parameters individually, so we can no
longer add new params to `glob()`.
In particular, we need to support `includeDotfiles` because we often configure
Buck to use Watchman to implement `glob()` in `BUCK` files, and when Watchman is
used in Eden, it leverages Eden's Thrift API to implement `glob()`. Because
Buck's `glob()` has an `include_dotfiles` option, we must be able to honor it
and pass it all the way through to Eden's `glob()` implementation.
Rather than name the new API `glob2()`, I'm electing to go with `globFiles()`.
(Perhaps once we eliminate all known users of `glob()` in the wild, which
requires turning over the current version of Watchman we have deployed, we can
redefine `glob()` in `eden.thrift` to be the same as `globFiles()` and then
update everyone to use `glob()` again so it has the more intuitive name.)
Reviewed By: wez
Differential Revision: D7748870
fbshipit-source-id: 92438f9c41e4fbdbd6cdccca5fce0e41cc3e9b07
2018-05-03 00:41:34 +03:00
|
|
|
|
2020-10-29 23:31:37 +03:00
|
|
|
if expected_commits:
|
|
|
|
self.assertCountEqual(
|
|
|
|
expected_commits, self.client.globFiles(params).originHashes, msg=msg
|
|
|
|
)
|
2021-01-27 23:02:25 +03:00
|
|
|
|
|
|
|
def assert_glob_with_dtypes(
|
|
|
|
self,
|
|
|
|
globs: List[str],
|
2021-02-24 06:56:18 +03:00
|
|
|
expected_matches: List[Tuple[bytes, str]],
|
2021-01-27 23:02:25 +03:00
|
|
|
include_dotfiles: bool = False,
|
|
|
|
msg: Optional[str] = None,
|
|
|
|
) -> None:
|
|
|
|
params = GlobParams(
|
|
|
|
self.mount_path_bytes,
|
|
|
|
globs,
|
|
|
|
includeDotfiles=include_dotfiles,
|
|
|
|
wantDtype=True,
|
|
|
|
)
|
|
|
|
result = self.client.globFiles(params)
|
|
|
|
actual_results = zip(
|
2021-02-24 06:56:18 +03:00
|
|
|
result.matchingFiles,
|
2021-01-27 23:02:25 +03:00
|
|
|
(_dtype_to_str(dtype) for dtype in result.dtypes),
|
|
|
|
)
|
|
|
|
self.assertEqual(expected_matches, sorted(actual_results), msg=msg)
|
|
|
|
|
|
|
|
|
|
|
|
# Mac and Linux fortunately appear to share the same dtype definitions
|
|
|
|
_DT_DIR = 4
|
|
|
|
_DT_REG = 8
|
|
|
|
_DT_LNK = 10
|
|
|
|
|
|
|
|
|
|
|
|
def _dtype_to_str(value: int) -> str:
|
|
|
|
if value == _DT_REG:
|
|
|
|
return "f"
|
|
|
|
elif value == _DT_DIR:
|
|
|
|
return "d"
|
|
|
|
elif value == _DT_LNK:
|
|
|
|
return "l"
|
|
|
|
else:
|
|
|
|
logging.error(f"unexpected dtype {value!r}")
|
|
|
|
return "?"
|