xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
<root> / tests / ior / error.c (20abe12ed8e9d51b6d320eb59becfd41bc109493) (2,331B) (mode 100644) [raw]
#include <stic.h>

#include <sys/stat.h> /* chmod() */
#include <unistd.h> /* rmdir() */

#include <string.h> /* strstr() */

#include <test-utils.h>

#include "../../src/compat/os.h"
#include "../../src/io/ior.h"

#include "utils.h"

static IoErrCbResult handle_errors(struct io_args_t *args,
		const ioe_err_t *err);

static int ignore_count;

TEST(file_removal_error_is_reported_and_logged_once, IF(not_windows))
{
	os_mkdir(SANDBOX_PATH "/dir", 0700);
	create_empty_file(SANDBOX_PATH "/dir/file");
	assert_success(chmod(SANDBOX_PATH "/dir", 0500));

	{
		io_args_t args = {
			.arg1.path = TEST_DATA_PATH "/dir",

			.result.errors_cb = &handle_errors,
		};
		ioe_errlst_init(&args.result.errors);

		ignore_count = 0;
		assert_int_equal(IO_RES_ABORTED, ior_rm(&args));
		assert_int_equal(0, ignore_count);

		/* Second error must be about failure to remove directory, first one is
		 * ignored and doesn't make it into the list. */
		assert_int_equal(1, args.result.errors.error_count);
		ioe_errlst_free(&args.result.errors);
	}

	assert_success(chmod(SANDBOX_PATH "/dir", 0700));
	delete_file(SANDBOX_PATH "/dir/file");
	rmdir(SANDBOX_PATH "/dir");
}

TEST(path_in_errors_has_no_double_slashes, IF(regular_unix_user))
{
	io_args_t args = {
		.arg1.src = SANDBOX_PATH "/dir",
		.arg2.dst = SANDBOX_PATH "/dir2",
		.arg3.crs = IO_CRS_REPLACE_FILES,

		.result.errors = IOE_ERRLST_INIT,
	};

	assert_success(os_mkdir(SANDBOX_PATH "/dir", 0700));
	create_empty_file(SANDBOX_PATH "/dir/afile");
	create_empty_file(SANDBOX_PATH "/dir/file");
	assert_success(chmod(SANDBOX_PATH "/dir/file", 0000));
	assert_success(os_mkdir(SANDBOX_PATH "/dir2", 0000));

	assert_int_equal(IO_RES_FAILED, ior_cp(&args));
	assert_int_equal(1, args.result.errors.error_count);
	assert_string_equal(NULL, strstr(args.result.errors.errors[0].path, "//"));
	ioe_errlst_free(&args.result.errors);

	delete_file(SANDBOX_PATH "/dir/afile");
	delete_file(SANDBOX_PATH "/dir/file");
	delete_dir(SANDBOX_PATH "/dir");
	delete_dir(SANDBOX_PATH "/dir2");
}

static IoErrCbResult
handle_errors(struct io_args_t *args, const ioe_err_t *err)
{
	if(ignore_count > 0)
	{
		--ignore_count;
		return IO_ECR_IGNORE;
	}

	return IO_ECR_BREAK;
}

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master