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> / src / fops_cpmv.c (88aaa8922c4fefccecef47be82e340bbfc62e3a0) (18KiB) (mode 100644) [raw]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
/* vifm
 * Copyright (C) 2001 Ken Steen.
 * Copyright (C) 2011 xaizek.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "fops_cpmv.h"

#include <assert.h> /* assert() */
#include <string.h> /* strcmp() strdup() */

#include "compat/reallocarray.h"
#include "modes/dialogs/msg_dialog.h"
#include "ui/cancellation.h"
#include "ui/fileview.h"
#include "ui/statusbar.h"
#include "utils/fs.h"
#include "utils/path.h"
#include "utils/str.h"
#include "utils/string_array.h"
#include "filelist.h"
#include "flist_pos.h"
#include "fops_common.h"
#include "fops_misc.h"
#include "ops.h"
#include "trash.h"
#include "undo.h"

/* Arguments pack for fops_query_list() verification function. */
typedef struct
{
	view_t *view;         /* Source view. */
	const char *dst_path; /* Destination directory. */
	int force;            /* Whether name conflicts should be ignored. */
	CopyMoveLikeOp op;    /* Operation. */
}
verify_args_t;

static int cp_file(const char src_dir[], const char dst_dir[], const char src[],
		const char dst[], CopyMoveLikeOp op, int cancellable, ops_t *ops,
		int force);
static int is_erroneous(view_t *view, const char dst_dir[], int force);
static int cpmv_prepare(view_t *view, char ***list, int *nlines,
		CopyMoveLikeOp op, int ignore_conflicts, char undo_msg[],
		size_t undo_msg_len, char dst_path[], size_t dst_path_len, int *from_file);
static int verify_list(char *files[], int nfiles, char *names[], int nnames,
		char **error, void *data);
static int check_for_clashes(verify_args_t *args, char *list[], char *marked[],
		int nlines, char **error);
static const char * cmlo_to_str(CopyMoveLikeOp op);
static void cpmv_files_in_bg(bg_op_t *bg_op, void *arg);
static void set_cpmv_bg_descr(bg_op_t *bg_op, bg_args_t *args, size_t i);
static void cpmv_file_in_bg(ops_t *ops, const char src[], const char dst[],
		int move, int force, int skip, int from_trash, const char dst_dir[]);
static int cp_file_f(const char src[], const char dst[], CopyMoveLikeOp op,
		int bg, int cancellable, ops_t *ops, int force);

int
fops_cpmv(view_t *view, char *list[], int nlines, CopyMoveLikeOp op, int flags)
{
	const int force = (flags & CMLF_FORCE);
	const int skip = (flags & CMLF_SKIP);

	int err;
	int nmarked_files;
	int custom_fnames;
	int i;
	char undo_msg[COMMAND_GROUP_INFO_LEN + 1];
	dir_entry_t *entry;
	char dst_dir[PATH_MAX + 1];
	int from_file;
	ops_t *ops;

	if((op == CMLO_LINK_REL || op == CMLO_LINK_ABS) && !symlinks_available())
	{
		show_error_msg("Symbolic Links Error",
				"Your OS doesn't support symbolic links");
		return 0;
	}

	const int ignore_conflicts = (force || skip);
	err = cpmv_prepare(view, &list, &nlines, op, ignore_conflicts, undo_msg,
			sizeof(undo_msg), dst_dir, sizeof(dst_dir), &from_file);
	if(err != 0)
	{
		return err > 0;
	}

	if(is_erroneous(view, dst_dir, force))
	{
		return 0;
	}

	switch(op)
	{
		case CMLO_COPY:
			ops = fops_get_ops(OP_COPY, "Copying", flist_get_dir(view), dst_dir);
			break;
		case CMLO_MOVE:
			ops = fops_get_ops(OP_MOVE, "Moving", flist_get_dir(view), dst_dir);
			break;
		case CMLO_LINK_REL:
		case CMLO_LINK_ABS:
			ops = fops_get_ops(OP_SYMLINK, "Linking", flist_get_dir(view), dst_dir);
			break;

		default:
			assert(0 && "Unexpected operation type.");
			return 0;
	}

	nmarked_files = fops_enqueue_marked_files(ops, view, dst_dir, 0);

	un_group_open(undo_msg);
	i = 0;
	entry = NULL;
	custom_fnames = (nlines > 0);
	while(iter_marked_entries(view, &entry) && !ui_cancellation_requested())
	{
		/* Must be at this level as dst might point into this buffer. */
		char src_full[PATH_MAX + 1];

		char dst_full[PATH_MAX + 8];
		const char *dst = (custom_fnames ? list[i] : entry->name);
		int err, from_trash;
		int skipped = 0;

		get_full_path_of(entry, sizeof(src_full), src_full);
		from_trash = trash_has_path(src_full);

		if(from_trash && !custom_fnames)
		{
			snprintf(src_full, sizeof(src_full), "%s/%s", entry->origin, dst);
			chosp(src_full);
			dst = trash_get_real_name_of(src_full);
		}

		snprintf(dst_full, sizeof(dst_full), "%s/%s", dst_dir, dst);
		if(path_exists(dst_full, NODEREF))
		{
			if(skip)
			{
				skipped = 1;
			}
			else if(force && !from_trash)
			{
				(void)perform_operation(OP_REMOVESL, NULL, NULL, dst_full, NULL);
			}
		}

		if(op == CMLO_COPY)
		{
			fops_progress_msg("Copying files", i, nmarked_files);
		}
		else if(op == CMLO_MOVE)
		{
			fops_progress_msg("Moving files", i, nmarked_files);
		}

		if(skipped)
		{
			/* Nothing to do for this path. */
			err = 0;
		}
		else if(op == CMLO_MOVE)
		{
			err = fops_mv_file(entry->name, entry->origin, dst, dst_dir, OP_MOVE, 1,
					ops);
			if(err != 0)
			{
				view->list_pos = fpos_find_by_name(view, entry->name);
			}
		}
		else
		{
			err = cp_file(entry->origin, dst_dir, entry->name, dst, op, 1, ops,
					0);
		}

		ops_advance(ops, err == 0);

		++i;
	}
	un_group_close();

	if(flist_custom_active(view) || pane_in_dir(view, dst_dir))
	{
		ui_view_schedule_reload(view);
	}
	ui_view_schedule_reload(view == curr_view ? other_view : curr_view);

	if(from_file)
	{
		free_string_array(list, nlines);
	}

	ui_sb_msgf("%d file%s successfully processed%s", ops->succeeded,
			(ops->succeeded == 1) ? "" : "s", fops_get_cancellation_suffix());

	fops_free_ops(ops);

	return 1;
}

void
fops_replace_entry(ops_t *ops, view_t *src, const dir_entry_t *src_entry,
		view_t *dst, dir_entry_t *dst_entry)
{
	void *cp = (void *)(size_t)1;
	int dst_exists = !fentry_is_fake(dst_entry);

	char dst_dir[PATH_MAX + 1];
	if(dst_exists)
	{
		copy_str(dst_dir, sizeof(dst_dir), dst_entry->origin);
	}
	else
	{
		const char *src_tail = src_entry->origin + strlen(flist_get_dir(src));
		build_path(dst_dir, sizeof(dst_dir), flist_get_dir(dst), src_tail);
	}

	char dst_full[PATH_MAX + 1];
	build_path(dst_full, sizeof(dst_full), dst_dir, src_entry->name);

	char src_full[PATH_MAX + 1];
	get_full_path_of(src_entry, sizeof(src_full), src_full);

	if(paths_are_same(src_full, dst_full))
	{
		/* Nothing to do if destination and source are the same file. */
		return;
	}

	/* Deleting it explicitly instead of letting cp_file() do it to move the file
	 * to trash and make operation reversible. */
	if(dst_exists && path_exists(dst_full, NODEREF))
	{
		fops_delete_entry(ops, dst, dst_entry, /*use_trash=*/1, /*nested=*/1);
	}

	fops_progress_msg("Copying files", 0, 1);

	if(fops_active(ops) && !is_valid_dir(dst_dir) &&
			perform_operation(OP_MKDIR, ops, cp, dst_dir, NULL) == OPS_SUCCEEDED)
	{
		un_group_add_op(OP_MKDIR, cp, NULL, dst_dir, "");
	}

	if(fops_active(ops))
	{
		/* Not forcing as destination path shouldn't exist. */
		if(cp_file_f(src_full, dst_full, CMLO_COPY, /*bg=*/0, /*cancellable=*/1,
					ops, /*force=*/0) == 0 && !dst_exists)
		{
			/* Update the destination entry to not be fake. */
			replace_string(&dst_entry->name, src_entry->name);
			replace_string(&dst_entry->origin, dst_dir);
		}
	}

	ui_view_schedule_reload(dst);
}

/* Adapter for cp_file_f() that accepts paths broken into directory/file
 * parts. */
static int
cp_file(const char src_dir[], const char dst_dir[], const char src[],
		const char dst[], CopyMoveLikeOp op, int cancellable, ops_t *ops, int force)
{
	char full_src[PATH_MAX + 1], full_dst[PATH_MAX + 1];

	to_canonic_path(src, src_dir, full_src, sizeof(full_src));
	to_canonic_path(dst, dst_dir, full_dst, sizeof(full_dst));

	return cp_file_f(full_src, full_dst, op, 0, cancellable, ops, force);
}

int
fops_cpmv_bg(view_t *view, char *list[], int nlines, int move, int flags)
{
	const int force = (flags & CMLF_FORCE);
	const int skip = (flags & CMLF_SKIP);

	int err;
	size_t i;
	char task_desc[COMMAND_GROUP_INFO_LEN];

	bg_args_t *args = calloc(1, sizeof(*args));
	if(args == NULL)
	{
		show_error_msg("Can't perform operation", "Out of memory");
		return 0;
	}

	args->nlines = nlines;
	args->move = move;
	args->force = force;
	args->skip = skip;

	const int ignore_conflicts = (force || skip);
	err = cpmv_prepare(view, &list, &args->nlines, move ? CMLO_MOVE : CMLO_COPY,
			ignore_conflicts, task_desc, sizeof(task_desc), args->path,
			sizeof(args->path), &args->from_file);
	if(err != 0)
	{
		fops_free_bg_args(args);
		return err > 0;
	}

	if(is_erroneous(view, args->path, force))
	{
		fops_free_bg_args(args);
		return 0;
	}

	args->list = args->from_file ? list :
	             args->nlines > 0 ? copy_string_array(list, nlines) : NULL;

	fops_prepare_for_bg_task(view, args);

	args->is_in_trash = malloc(args->sel_list_len);
	for(i = 0U; i < args->sel_list_len; ++i)
	{
		args->is_in_trash[i] = trash_has_path(args->sel_list[i]);
	}

	if(args->list == NULL)
	{
		int i;
		args->nlines = args->sel_list_len;
		args->list = reallocarray(NULL, args->nlines, sizeof(*args->list));
		for(i = 0; i < args->nlines; ++i)
		{
			args->list[i] =
				strdup(fops_get_dst_name(args->sel_list[i], args->is_in_trash[i]));
		}
	}

	args->ops = fops_get_bg_ops(move ? OP_MOVE : OP_COPY,
			move ? "moving" : "copying", args->path);

	if(bg_execute(task_desc, "...", args->sel_list_len, 1, &cpmv_files_in_bg,
				args) != 0)
	{
		fops_free_bg_args(args);

		show_error_msg("Can't process files",
				"Failed to initiate background operation");
	}

	return 0;
}

/* Checks operation for adequacy.  Displays error message in case of issues.
 * Returns non-zero if operation must be aborted, otherwise zero is returned. */
static int
is_erroneous(view_t *view, const char dst_dir[], int force)
{
	const int same_dir = pane_in_dir(view, dst_dir);
	if(same_dir && force)
	{
		show_error_msg("Operation Aborted",
				"Forcing overwrite when destination and source is the same directory "
				"will lead to losing data.");
		return 1;
	}
	return 0;
}

/* Performs general preparations for file copy/move-like operations: resolving
 * destination path, validating names, checking for conflicts, formatting undo
 * message.  Returns zero on success, otherwise positive number for status bar
 * message and negative number for other errors. */
static int
cpmv_prepare(view_t *view, char ***list, int *nlines, CopyMoveLikeOp op,
		int ignore_conflicts, char undo_msg[], size_t undo_msg_len, char dst_path[],
		size_t dst_path_len, int *from_file)
{
	view_t *const other = (view == curr_view) ? other_view : curr_view;

	if(op == CMLO_MOVE)
	{
		if(!fops_view_can_be_changed(view))
		{
			return -1;
		}
	}
	else if(op == CMLO_COPY && !fops_can_read_marked_files(view))
	{
		return -1;
	}

	if(*nlines == 1)
	{
		if(fops_check_dir_path(other, (*list)[0], dst_path, dst_path_len))
		{
			*nlines = 0;
		}
	}
	else
	{
		copy_str(dst_path, dst_path_len, fops_get_dst_dir(other, -1));
	}

	if(!fops_view_can_be_extended(other, -1) ||
			!fops_is_dir_writable(DR_DESTINATION, dst_path))
	{
		return -1;
	}

	size_t nmarked;
	char **marked = fops_grab_marked_files(view, &nmarked);

	/* Custom views can contain several files with the same name. */
	if(*nlines == 0 && flist_custom_active(view))
	{
		size_t i;
		for(i = 0U; i < nmarked; ++i)
		{
			if(is_in_string_array(marked, i, marked[i]))
			{
				ui_sb_errf("Source name \"%s\" duplicates", marked[i]);
				free_string_array(marked, nmarked);
				return 1;
			}
		}
	}

	verify_args_t verify_args = {
		.view = view,
		.dst_path = dst_path,
		.force = ignore_conflicts,
		.op = op,
	};

	*from_file = (*nlines < 0);
	if(*from_file)
	{
		*list = fops_query_list(nmarked, marked, nlines, 1, &verify_list,
				&verify_args);
		if(*list == NULL)
		{
			free_string_array(marked, nmarked);
			return -1;
		}
	}

	char *error_str = NULL;
	int error = !verify_list(marked, nmarked, *list, *nlines, &error_str,
			&verify_args);

	free_string_array(marked, nmarked);

	if(error)
	{
		if(error_str != NULL)
		{
			ui_sb_err(error_str);
			free(error_str);
		}

		redraw_view(view);
		if(*from_file)
		{
			free_string_array(*list, *nlines);
		}
		return 1;
	}

	snprintf(undo_msg, undo_msg_len, "%s from %s to ", cmlo_to_str(op),
			replace_home_part(flist_get_dir(view)));
	snprintf(undo_msg + strlen(undo_msg), undo_msg_len - strlen(undo_msg),
			"%s: ", replace_home_part(dst_path));
	fops_append_marked_files(view, undo_msg, (*nlines > 0) ? *list : NULL);

	return 0;
}

/* Checks that operation can be performed.  Returns non-zero if so, otherwise
 * zero is returned along with setting *error. */
static int
verify_list(char *files[], int nfiles, char *names[], int nnames, char **error,
		void *data)
{
	verify_args_t *args = data;

	int ok = 1;

	if(nnames > 0 &&
			(!fops_is_name_list_ok(nfiles, nnames, names, NULL, error) ||
			!fops_is_copy_list_ok(args->dst_path, nnames, names, args->force, error)))
	{
		ok = 0;
	}
	else if(nnames == 0 &&
			!fops_is_copy_list_ok(args->dst_path, nfiles, files, args->force, error))
	{
		ok = 0;
	}

	if(ok && check_for_clashes(args, names, files, nnames, error) != 0)
	{
		ok = 0;
	}

	return ok;
}

/* Checks whether operation is OK from the point of view of losing files due to
 * tree clashes (child move over parent or vice versa).  Reallocates *error to
 * provide error message.  Returns zero if everything is fine, otherwise
 * non-zero is returned. */
static int
check_for_clashes(verify_args_t *args, char *list[], char *marked[], int nlines,
		char **error)
{
	const int is_cpmv = ONE_OF(args->op, CMLO_MOVE, CMLO_COPY);

	dir_entry_t *entry = NULL;
	int i = 0;
	while(iter_marked_entries(args->view, &entry))
	{
		char src_full[PATH_MAX + 1], dst_full[PATH_MAX + 1];
		const char *const dst_name = (nlines > 0) ? list[i] : marked[i];
		++i;

		get_full_path_of(entry, sizeof(src_full), src_full);

		snprintf(dst_full, sizeof(dst_full), "%s/%s", args->dst_path, dst_name);
		chosp(dst_full);

		if(is_cpmv && is_in_subtree(dst_full, src_full, 0))
		{
			put_string(error, format_str("Can't move/copy parent inside itself: %s",
						replace_home_part(src_full)));
			return 1;
		}

		if(is_in_subtree(src_full, dst_full, 0))
		{
			put_string(error,
					format_str("Operation would result in losing contents of %s",
						replace_home_part(src_full)));
			return 1;
		}
	}
	return 0;
}

/* Gets string representation of a copy/move-like operation.  Returns the
 * string. */
static const char *
cmlo_to_str(CopyMoveLikeOp op)
{
	switch(op)
	{
		case CMLO_COPY:
			return "copy";
		case CMLO_MOVE:
			return "move";
		case CMLO_LINK_REL:
			return "rlink";
		case CMLO_LINK_ABS:
			return "alink";

		default:
			assert(0 && "Unexpected operation type.");
			return "";
	}
}

/* Entry point for a background task that copies/moves files. */
static void
cpmv_files_in_bg(bg_op_t *bg_op, void *arg)
{
	size_t i;
	bg_args_t *const args = arg;
	ops_t *ops = args->ops;
	fops_bg_ops_init(ops, bg_op);

	if(ops->use_system_calls)
	{
		size_t i;
		bg_op_set_descr(bg_op, "estimating...");
		for(i = 0U; i < args->sel_list_len; ++i)
		{
			const char *const src = args->sel_list[i];
			const char *const dst = args->list[i];
			ops_enqueue(ops, src, dst);
		}
	}

	for(i = 0U; i < args->sel_list_len; ++i)
	{
		const char *const src = args->sel_list[i];
		const char *const dst = args->list[i];

		set_cpmv_bg_descr(bg_op, args, i);

		cpmv_file_in_bg(ops, src, dst, args->move, args->force, args->skip,
				args->is_in_trash[i], args->path);
		++bg_op->done;
	}

	fops_free_bg_args(args);
}

/* Sets nice title for the background job. */
static void
set_cpmv_bg_descr(bg_op_t *bg_op, bg_args_t *args, size_t i)
{
	const char *src = args->sel_list[i];

	/* Start with the source path. */
	const char *descr = src;

	/* Try shorten the path using tilde and use that if it worked. */
	char *tilde_src = make_tilde_path(src);
	if(tilde_src != NULL)
	{
		descr = tilde_src;
	}

	/* In case there are multiple files to process, prepend current position. */
	char *stats = NULL;
	if(args->sel_list_len > 1)
	{
		/* The space is doubled for the symmetry with progress appended by the job
		 * bar. */
		stats = format_str("%d/%d  %s", (int)i + 1, (int)args->sel_list_len, descr);
	}
	if(stats != NULL)
	{
		descr = stats;
	}

	bg_op_set_descr(bg_op, descr);

	free(tilde_src);
	free(stats);
}

/* Actual implementation of background file copying/moving. */
static void
cpmv_file_in_bg(ops_t *ops, const char src[], const char dst[], int move,
		int force, int skip, int from_trash, const char dst_dir[])
{
	char dst_full[PATH_MAX + 1];
	snprintf(dst_full, sizeof(dst_full), "%s/%s", dst_dir, dst);
	if(path_exists(dst_full, NODEREF))
	{
		if(skip)
		{
			return;
		}

		if(force && !from_trash)
		{
			(void)perform_operation(OP_REMOVESL, NULL, (void *)1, dst_full, NULL);
		}
	}

	if(move)
	{
		(void)fops_mv_file_f(src, dst_full, OP_MOVE, 1, 1, ops);
	}
	else
	{
		(void)cp_file_f(src, dst_full, CMLO_COPY, 1, 1, ops, 0);
	}
}

/* Copies file from one location to another.  Returns zero on success, otherwise
 * non-zero is returned. */
static int
cp_file_f(const char src[], const char dst[], CopyMoveLikeOp op, int bg,
		int cancellable, ops_t *ops, int force)
{
	if(strcmp(src, dst) == 0)
	{
		return 0;
	}

	OPS file_op;
	char rel_path[PATH_MAX + 1];
	if(op == CMLO_COPY)
	{
		file_op = force ? OP_COPYF : OP_COPY;
	}
	else
	{
		file_op = OP_SYMLINK;

		if(op == CMLO_LINK_REL)
		{
			char dst_dir[PATH_MAX + 1];

			copy_str(dst_dir, sizeof(dst_dir), dst);
			remove_last_path_component(dst_dir);

			copy_str(rel_path, sizeof(rel_path), make_rel_path(src, dst_dir));
			src = rel_path;
		}
	}

	OpsResult result = perform_operation(file_op, ops,
			cancellable ? NULL : (void *)1, src, dst);
	if(result != OPS_SUCCEEDED)
	{
		return 1;
	}

	if(!bg)
	{
		un_group_add_op(file_op, NULL, NULL, src, dst);
	}
	return 0;
}

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 : */
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