Skip to content

Commit

Permalink
UTILS: remove unused code (files manipulations)
Browse files Browse the repository at this point in the history
Reviewed-by: Iker Pedrosa <[email protected]>
Reviewed-by: Sumit Bose <[email protected]>
  • Loading branch information
alexey-tikhonov committed Aug 25, 2023
1 parent 01131ba commit 15a2213
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 792 deletions.
4 changes: 0 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ AC_SEARCH_LIBS([clock_gettime], [rt posix4],
AC_SUBST([LIBCLOCK_GETTIME])
LIBS=$SAVE_LIBS

# Check for presence of modern functions for setting file timestamps
AC_CHECK_FUNCS([ utimensat \
futimens ])

AC_CHECK_FUNCS([ explicit_bzero ])

# Check for the timegm() function (not part of POSIX / Open Group specs)
Expand Down
174 changes: 0 additions & 174 deletions src/tests/files-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,176 +204,6 @@ START_TEST(test_remove_subtree)
}
END_TEST

START_TEST(test_simple_copy)
{
int ret;
char origpath[PATH_MAX+1];
char *tmp;

errno = 0;
ck_assert_msg(getcwd(origpath, PATH_MAX) == origpath, "Cannot getcwd\n");
ck_assert_msg(errno == 0, "Cannot getcwd\n");

/* create a file */
ret = chdir(dir_path);
sss_ck_fail_if_msg(ret == -1, "Cannot chdir1\n");

ret = create_simple_file("bar", "bar");
sss_ck_fail_if_msg(ret == -1, "Cannot create file1\n");

/* create a subdir and file inside it */
ret = mkdir("subdir", 0700);
sss_ck_fail_if_msg(ret == -1, "Cannot create subdir\n");

ret = chdir("subdir");
sss_ck_fail_if_msg(ret == -1, "Cannot chdir\n");

ret = create_simple_file("foo", "foo");
sss_ck_fail_if_msg(ret == -1, "Cannot create file\n");

/* go back */
ret = chdir(origpath);
sss_ck_fail_if_msg(ret == -1, "Cannot chdir\n");

/* and finally copy.. */
DEBUG(SSSDBG_FUNC_DATA,
"Will copy from '%s' to '%s'\n", dir_path, dst_path);
ret = sss_copy_tree(dir_path, dst_path, 0700, uid, gid);
ck_assert_msg(ret == EOK, "copy_tree failed\n");

/* check if really copied */
ret = access(dst_path, F_OK);
ck_assert_msg(ret == 0, "destination directory not there\n");

tmp = talloc_asprintf(test_ctx, "%s/bar", dst_path);
ret = check_file(tmp, uid, gid, S_IFREG|S_IRWXU, 0, NULL, false);
ck_assert_msg(ret == EOK, "Cannot open %s\n", tmp);
talloc_free(tmp);
}
END_TEST

START_TEST(test_copy_file)
{
TALLOC_CTX *tmp_ctx = talloc_new(test_ctx);
int ret;
char origpath[PATH_MAX+1];
char *foo_path;
char *bar_path;

errno = 0;
ck_assert_msg(getcwd(origpath, PATH_MAX) == origpath, "Cannot getcwd\n");
ck_assert_msg(errno == 0, "Cannot getcwd\n");

/* create a file */
ret = chdir(dir_path);
sss_ck_fail_if_msg(ret == -1, "Cannot chdir1\n");

ret = create_simple_file("foo", "foo");
sss_ck_fail_if_msg(ret == -1, "Cannot create foo\n");
foo_path = talloc_asprintf(tmp_ctx, "%s/foo", dir_path);
bar_path = talloc_asprintf(tmp_ctx, "%s/bar", dst_path);

/* create a file */
ret = chdir(origpath);
sss_ck_fail_if_msg(ret == -1, "Cannot chdir1\n");

/* Copy this file to a new file */
DEBUG(SSSDBG_FUNC_DATA,
"Will copy from 'foo' to 'bar'\n");
ret = sss_copy_file_secure(foo_path, bar_path, 0700, uid, gid, 0);
ck_assert_msg(ret == EOK, "copy_file_secure failed\n");

/* check if really copied */
ret = access(bar_path, F_OK);
ck_assert_msg(ret == 0, "destination file 'bar' not there\n");

ret = check_file(bar_path, uid, gid, S_IFREG|S_IRWXU, 0, NULL, false);
ck_assert_msg(ret == EOK, "Cannot open %s\n", bar_path);
talloc_free(tmp_ctx);
}
END_TEST

START_TEST(test_copy_symlink)
{
int ret;
char origpath[PATH_MAX+1];
char *tmp;
struct stat statbuf;

errno = 0;
ck_assert_msg(getcwd(origpath, PATH_MAX) == origpath, "Cannot getcwd\n");
ck_assert_msg(errno == 0, "Cannot getcwd\n");

/* create a subdir */
ret = chdir(dir_path);
sss_ck_fail_if_msg(ret == -1, "Cannot chdir\n");

ret = create_simple_file("footarget", "foo");
sss_ck_fail_if_msg(ret == -1, "Cannot create file\n");

ret = symlink("footarget", "foolink");
sss_ck_fail_if_msg(ret == -1, "Cannot create symlink\n");

/* go back */
ret = chdir(origpath);
sss_ck_fail_if_msg(ret == -1, "Cannot chdir\n");

/* and finally copy.. */
DEBUG(SSSDBG_FUNC_DATA,
"Will copy from '%s' to '%s'\n", dir_path, dst_path);
ret = sss_copy_tree(dir_path, dst_path, 0700, uid, gid);
ck_assert_msg(ret == EOK, "copy_tree failed\n");

/* check if really copied */
ret = access(dst_path, F_OK);
ck_assert_msg(ret == 0, "destination directory not there\n");

tmp = talloc_asprintf(test_ctx, "%s/foolink", dst_path);
ret = lstat(tmp, &statbuf);
ck_assert_msg(ret == 0, "cannot stat the symlink %s\n", tmp);
ck_assert_msg(S_ISLNK(statbuf.st_mode), "%s not a symlink?\n", tmp);
talloc_free(tmp);
}
END_TEST

START_TEST(test_copy_node)
{
int ret;
char origpath[PATH_MAX+1];
char *tmp;

errno = 0;
ck_assert_msg(getcwd(origpath, PATH_MAX) == origpath, "Cannot getcwd\n");
ck_assert_msg(errno == 0, "Cannot getcwd\n");

/* create a node */
ret = chdir(dir_path);
sss_ck_fail_if_msg(ret == -1, "Cannot chdir\n");

ret = mknod("testnode", S_IFIFO | S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, 0);
ck_assert_msg(ret == 0, "cannot stat /dev/null: %s", strerror(errno));

/* go back */
ret = chdir(origpath);
sss_ck_fail_if_msg(ret == -1, "Cannot chdir\n");

/* and finally copy.. */
DEBUG(SSSDBG_FUNC_DATA,
"Will copy from '%s' to '%s'\n", dir_path, dst_path);
ret = sss_copy_tree(dir_path, dst_path, 0700, uid, gid);
ck_assert_msg(ret == EOK, "copy_tree failed\n");

/* check if really copied and without special files */
ret = access(dst_path, F_OK);
ck_assert_msg(ret == 0, "destination directory not there\n");

tmp = talloc_asprintf(test_ctx, "%s/testnode", dst_path);
ret = access(tmp, F_OK);
ck_assert_msg(ret == -1, "special file %s exists, it shouldn't\n", tmp);
talloc_free(tmp);
}
END_TEST

START_TEST(test_create_dir)
{
int ret;
Expand Down Expand Up @@ -421,10 +251,6 @@ static Suite *files_suite(void)

tcase_add_test(tc_files, test_remove_tree);
tcase_add_test(tc_files, test_remove_subtree);
tcase_add_test(tc_files, test_simple_copy);
tcase_add_test(tc_files, test_copy_file);
tcase_add_test(tc_files, test_copy_symlink);
tcase_add_test(tc_files, test_copy_node);
tcase_add_test(tc_files, test_create_dir);
suite_add_tcase(s, tc_files);

Expand Down
Loading

0 comments on commit 15a2213

Please sign in to comment.