Exemple #1
0
/* Navigates the view to given mark if it's valid.  Returns new value for
 * save_msg flag. */
static int
navigate_to_bookmark(FileView *view, char mark)
{
	const bookmark_t *const bmark = get_bmark_by_name(mark);

	if(is_bmark_valid(bmark))
	{
		/* Do not change directory if we already there. */
		if(!paths_are_equal(view->curr_dir, bmark->directory))
		{
			if(change_directory(view, bmark->directory) >= 0)
			{
				load_dir_list(view, 1);
			}
		}

		if(paths_are_equal(view->curr_dir, bmark->directory))
		{
			(void)ensure_file_is_selected(view, bmark->file);
		}
	}
	else
	{
		if(!char_is_one_of(valid_bookmarks, mark))
			status_bar_message("Invalid mark name");
		else if(is_bmark_empty(bmark))
			status_bar_message("Mark is not set");
		else
			status_bar_message("Mark is invalid");

		move_to_list_pos(view, view->list_pos);
		return 1;
	}
	return 0;
}
Exemple #2
0
int
check_mark_directory(FileView *view, char m)
{
	const mark_t *const mark = get_mark_by_name(m);

	if(is_empty(mark))
	{
		return -1;
	}

	if(flist_custom_active(view))
	{
		dir_entry_t *entry;
		char path[PATH_MAX];
		snprintf(path, sizeof(path), "%s/%s", mark->directory, mark->file);
		entry = entry_from_path(view->dir_entry, view->list_rows, path);
		if(entry != NULL)
		{
			return entry_to_pos(view, entry);
		}
	}
	else if(paths_are_equal(view->curr_dir, mark->directory))
	{
		return find_file_pos_in_list(view, mark->file);
	}

	return -1;
}
Exemple #3
0
/* Searches for mount record by path to mount point. */
static fuse_mount_t *
get_mount_by_mount_point(const char dir[])
{
	fuse_mount_t *runner = fuse_mounts;
	while(runner != NULL)
	{
		if(paths_are_equal(runner->mount_point, dir))
			break;
		runner = runner->next;
	}
	return runner;
}
Exemple #4
0
/* Searchers for mount record by source file path. */
static fuse_mount_t *
get_mount_by_source(const char source[])
{
	fuse_mount_t *runner = fuse_mounts;
	while(runner != NULL)
	{
		if(paths_are_equal(runner->source_file_name, source))
			break;
		runner = runner->next;
	}
	return runner;
}
Exemple #5
0
int
check_mark_directory(FileView *view, char mark)
{
	const bookmark_t *const bmark = get_bmark_by_name(mark);

	if(!is_bmark_empty(bmark))
	{
		if(paths_are_equal(view->curr_dir, bmark->directory))
		{
			return find_file_pos_in_list(view, bmark->file);
		}
	}

	return -1;
}
Exemple #6
0
TEST(chase_links_is_not_affected_by_chdir, IF(not_windows))
{
	char pwd[PATH_MAX];

	assert_success(os_mkdir("dir", 0700));

	/* symlink() is not available on Windows, but other code is fine. */
#ifndef _WIN32
	assert_success(symlink("dir", "dir-link"));
#endif

	assert_non_null(get_cwd(pwd, sizeof(pwd)));
	strcpy(curr_view->curr_dir, pwd);

	assert_true(change_directory(curr_view, "dir-link") >= 0);
	assert_success(chdir(".."));
	assert_true(change_directory(curr_view, "..") >= 0);
	assert_true(paths_are_equal(curr_view->curr_dir, pwd));

	assert_success(rmdir("dir"));
	assert_success(remove("dir-link"));
}
Exemple #7
0
int
fuse_try_unmount(FileView *view)
{
	char buf[14 + PATH_MAX + 1];
	fuse_mount_t *runner, *trailer;
	int status;
	fuse_mount_t *sniffer;
	char *escaped_mount_point;

	runner = fuse_mounts;
	trailer = NULL;
	while(runner)
	{
		if(paths_are_equal(runner->mount_point, view->curr_dir))
		{
			break;
		}

		trailer = runner;
		runner = runner->next;
	}

	if(runner == NULL)
	{
		return 0;
	}

	/* we are exiting a top level dir */
	escaped_mount_point = escape_filename(runner->mount_point, 0);
	snprintf(buf, sizeof(buf), "%s %s 2> /dev/null", curr_stats.fuse_umount_cmd,
			escaped_mount_point);
	LOG_INFO_MSG("FUSE unmount command: `%s`", buf);
	free(escaped_mount_point);

	/* Have to chdir to parent temporarily, so that this DIR can be unmounted. */
	if(vifm_chdir(cfg.fuse_home) != 0)
	{
		show_error_msg("FUSE UMOUNT ERROR", "Can't chdir to FUSE home");
		return -1;
	}

	status_bar_message("FUSE unmounting selected file, please stand by..");
	status = background_and_wait_for_status(buf, 0, NULL);
	clean_status_bar();
	/* check child status */
	if(!WIFEXITED(status) || WEXITSTATUS(status))
	{
		werase(status_bar);
		show_error_msgf("FUSE UMOUNT ERROR", "Can't unmount %s.  It may be busy.",
				runner->source_file_name);
		(void)vifm_chdir(flist_get_dir(view));
		return -1;
	}

	/* remove the directory we created for the mount */
	if(path_exists(runner->mount_point, DEREF))
		rmdir(runner->mount_point);

	/* remove mount point from fuse_mount_t */
	sniffer = runner->next;
	if(trailer)
		trailer->next = sniffer ? sniffer : NULL;
	else
		fuse_mounts = sniffer;

	updir_from_mount(view, runner);
	free(runner);
	return 1;
}
Exemple #8
0
static int
cmd_dsync_run_local(struct dsync_cmd_context *ctx, struct mail_user *user,
		    struct dsync_brain *brain, struct dsync_ibc *ibc2,
		    bool *changes_during_sync_r)
{
	struct dsync_brain *brain2;
	struct mail_user *user2;
	struct setting_parser_context *set_parser;
	const char *set_line, *location;
	bool brain1_running, brain2_running, changed1, changed2;
	int ret;

	if (ctx->local_location_from_arg)
		location = ctx->ctx.args[0];
	else {
		i_assert(ctx->local_location != NULL);
		location = ctx->local_location;
	}

	i_set_failure_prefix("dsync(%s): ", user->username);

	/* update mail_location and create another user for the
	   second location. */
	set_parser = mail_storage_service_user_get_settings_parser(ctx->ctx.cur_service_user);
	set_line = t_strconcat("mail_location=", location, NULL);
	if (settings_parse_line(set_parser, set_line) < 0)
		i_unreached();
	ret = mail_storage_service_next(ctx->ctx.storage_service,
					ctx->ctx.cur_service_user, &user2);
	if (ret < 0) {
		ctx->ctx.exit_code = ret == -1 ? EX_TEMPFAIL : EX_CONFIG;
		return -1;
	}
	doveadm_user_init_dsync(user2);

	if (mail_namespaces_get_root_sep(user->namespaces) !=
	    mail_namespaces_get_root_sep(user2->namespaces)) {
		i_error("Mail locations must use the same "
			"virtual mailbox hierarchy separator "
			"(specify separator for the default namespace)");
		ctx->ctx.exit_code = EX_CONFIG;
		mail_user_unref(&user2);
		return -1;
	}
	if (paths_are_equal(user, user2, MAILBOX_LIST_PATH_TYPE_MAILBOX) &&
	    paths_are_equal(user, user2, MAILBOX_LIST_PATH_TYPE_INDEX)) {
		i_error("Both source and destination mail_location "
			"points to same directory: %s",
			mailbox_list_get_root_forced(user->namespaces->list,
						     MAILBOX_LIST_PATH_TYPE_MAILBOX));
		ctx->ctx.exit_code = EX_CONFIG;
		mail_user_unref(&user2);
		return -1;
	}

	brain2 = dsync_brain_slave_init(user2, ibc2, TRUE);
	mail_user_unref(&user2);

	brain1_running = brain2_running = TRUE;
	changed1 = changed2 = TRUE;
	while (brain1_running || brain2_running) {
		if (dsync_brain_has_failed(brain) ||
		    dsync_brain_has_failed(brain2))
			break;

		i_assert(changed1 || changed2);
		brain1_running = dsync_brain_run(brain, &changed1);
		brain2_running = dsync_brain_run(brain2, &changed2);
	}
	*changes_during_sync_r = dsync_brain_has_unexpected_changes(brain2);
	if (dsync_brain_deinit(&brain2) < 0) {
		ctx->ctx.exit_code = EX_TEMPFAIL;
		return -1;
	}
	return 0;
}