Skip to content

Commit df354ec

Browse files
committed
fs: remove mock naming from change ownership constants
The file ownership concepts can reflect the actual file ownership, they are not necessarily limited to mocking the interface. Rename them so that they can be more broadly applicable.
1 parent 78af6b5 commit df354ec

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

src/util/fs_path.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,9 +1785,9 @@ bool git_fs_path_supports_symlinks(const char *dir)
17851785
return supported;
17861786
}
17871787

1788-
static git_fs_path__mock_owner_t mock_owner = GIT_FS_PATH_MOCK_OWNER_NONE;
1788+
static git_fs_path_owner_t mock_owner = GIT_FS_PATH_OWNER_NONE;
17891789

1790-
void git_fs_path__set_owner(git_fs_path__mock_owner_t owner)
1790+
void git_fs_path__set_owner(git_fs_path_owner_t owner)
17911791
{
17921792
mock_owner = owner;
17931793
}
@@ -1885,7 +1885,7 @@ int git_fs_path_owner_is_current_user(bool *out, const char *path)
18851885
int error = -1;
18861886

18871887
if (mock_owner) {
1888-
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
1888+
*out = (mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
18891889
return 0;
18901890
}
18911891

@@ -1907,7 +1907,7 @@ int git_fs_path_owner_is_system(bool *out, const char *path)
19071907
PSID owner_sid;
19081908

19091909
if (mock_owner) {
1910-
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM);
1910+
*out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR);
19111911
return 0;
19121912
}
19131913

@@ -1927,8 +1927,8 @@ int git_fs_path_owner_is_system_or_current_user(bool *out, const char *path)
19271927
int error = -1;
19281928

19291929
if (mock_owner) {
1930-
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM ||
1931-
mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
1930+
*out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR ||
1931+
mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
19321932
return 0;
19331933
}
19341934

@@ -1986,7 +1986,7 @@ int git_fs_path_owner_is_current_user(bool *out, const char *path)
19861986
uid_t userid = geteuid();
19871987

19881988
if (mock_owner) {
1989-
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
1989+
*out = (mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
19901990
return 0;
19911991
}
19921992

@@ -1998,7 +1998,7 @@ int git_fs_path_owner_is_system(bool *out, const char *path)
19981998
uid_t userid = 0;
19991999

20002000
if (mock_owner) {
2001-
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM);
2001+
*out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR);
20022002
return 0;
20032003
}
20042004

@@ -2010,8 +2010,8 @@ int git_fs_path_owner_is_system_or_current_user(bool *out, const char *path)
20102010
uid_t userids[2] = { geteuid(), 0 };
20112011

20122012
if (mock_owner) {
2013-
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM ||
2014-
mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
2013+
*out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR ||
2014+
mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
20152015
return 0;
20162016
}
20172017

src/util/fs_path.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -732,18 +732,31 @@ int git_fs_path_normalize_slashes(git_str *out, const char *path);
732732
bool git_fs_path_supports_symlinks(const char *dir);
733733

734734
typedef enum {
735-
GIT_FS_PATH_MOCK_OWNER_NONE = 0, /* do filesystem lookups as normal */
736-
GIT_FS_PATH_MOCK_OWNER_SYSTEM = 1,
737-
GIT_FS_PATH_MOCK_OWNER_CURRENT_USER = 2,
738-
GIT_FS_PATH_MOCK_OWNER_OTHER = 3
739-
} git_fs_path__mock_owner_t;
735+
GIT_FS_PATH_OWNER_NONE = 0,
736+
737+
/** The file must be owned by the current user. */
738+
GIT_FS_PATH_OWNER_CURRENT_USER = (1 << 0),
739+
740+
/** The file must be owned by the system account. */
741+
GIT_FS_PATH_OWNER_ADMINISTRATOR = (1 << 1),
742+
743+
/**
744+
* The file may be owned by a system account if the current
745+
* user is in an administrator group. Windows only; this is
746+
* a noop on non-Windows systems.
747+
*/
748+
GIT_FS_PATH_OWNER_CURRENT_USER_IS_ADMINISTRATOR = (1 << 2),
749+
750+
/** The file may be owned by another user. */
751+
GIT_FS_PATH_OWNER_OTHER = (1 << 4)
752+
} git_fs_path_owner_t;
740753

741754
/**
742755
* Sets the mock ownership for files; subsequent calls to
743-
* `git_fs_path_owner_is_*` functions will return this data until cleared
744-
* with `GIT_FS_PATH_MOCK_OWNER_NONE`.
756+
* `git_fs_path_owner_is_*` functions will return this data until
757+
* cleared with `GIT_FS_PATH_OWNER_NONE`.
745758
*/
746-
void git_fs_path__set_owner(git_fs_path__mock_owner_t owner);
759+
void git_fs_path__set_owner(git_fs_path_owner_t owner);
747760

748761
/**
749762
* Verify that the file in question is owned by an administrator or system

tests/libgit2/repo/open.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void test_repo_open__cleanup(void)
2222
if (git_fs_path_isdir("alternate"))
2323
git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES);
2424

25-
git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_NONE);
25+
git_fs_path__set_owner(GIT_FS_PATH_OWNER_NONE);
2626

2727
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, config_path.ptr));
2828
git_buf_dispose(&config_path);
@@ -481,16 +481,16 @@ void test_repo_open__validates_dir_ownership(void)
481481
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
482482

483483
/* When the current user owns the repo config, that's acceptable */
484-
git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
484+
git_fs_path__set_owner(GIT_FS_PATH_OWNER_CURRENT_USER);
485485
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
486486
git_repository_free(repo);
487487

488488
/* When the system user owns the repo config, fail */
489-
git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_SYSTEM);
489+
git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR);
490490
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
491491

492492
/* When an unknown user owns the repo config, fail */
493-
git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER);
493+
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
494494
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
495495
}
496496

@@ -503,16 +503,16 @@ void test_repo_open__validates_bare_repo_ownership(void)
503503
cl_fixture_sandbox("testrepo.git");
504504

505505
/* When the current user owns the repo config, that's acceptable */
506-
git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
506+
git_fs_path__set_owner(GIT_FS_PATH_OWNER_CURRENT_USER);
507507
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
508508
git_repository_free(repo);
509509

510510
/* When the system user owns the repo config, fail */
511-
git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_SYSTEM);
511+
git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR);
512512
cl_git_fail(git_repository_open(&repo, "testrepo.git"));
513513

514514
/* When an unknown user owns the repo config, fail */
515-
git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER);
515+
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
516516
cl_git_fail(git_repository_open(&repo, "testrepo.git"));
517517
}
518518

@@ -528,7 +528,7 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void)
528528
cl_fixture_sandbox("empty_standard_repo");
529529
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
530530

531-
git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER);
531+
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
532532
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
533533

534534
/* Add safe.directory options to the global configuration */
@@ -572,7 +572,7 @@ void test_repo_open__can_allowlist_bare_gitdir(void)
572572

573573
cl_fixture_sandbox("testrepo.git");
574574

575-
git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER);
575+
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
576576
cl_git_fail(git_repository_open(&repo, "testrepo.git"));
577577

578578
/* Add safe.directory options to the global configuration */
@@ -617,7 +617,7 @@ void test_repo_open__can_reset_safe_directory_list(void)
617617
cl_fixture_sandbox("empty_standard_repo");
618618
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
619619

620-
git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER);
620+
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
621621
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
622622

623623
/* Add safe.directory options to the global configuration */

0 commit comments

Comments
 (0)