Exemplo n.º 1
0
Arquivo: path.c Projeto: jubalh/vifm
void
exclude_file_name(char path[])
{
	if(path_exists(path, DEREF) && !is_valid_dir(path))
	{
		remove_last_path_component(path);
	}
}
Exemplo n.º 2
0
/* Resolve link target and either navigate inside directory link points to or
 * navigate to directory where target is located pointing cursor on
 * it (the follow_dirs flag controls behaviour). */
static void
follow_link(FileView *view, int follow_dirs)
{
	char *dir, *file;
	char full_path[PATH_MAX];
	char linkto[PATH_MAX + NAME_MAX];
	dir_entry_t *const entry = &curr_view->dir_entry[curr_view->list_pos];

	get_full_path_of(entry, sizeof(full_path), full_path);

	if(get_link_target_abs(full_path, entry->origin, linkto, sizeof(linkto)) != 0)
	{
		show_error_msg("Error", "Can't read link.");
		return;
	}

	if(!path_exists(linkto, DEREF))
	{
		show_error_msg("Broken Link",
				"Can't access link destination.  It might be broken.");
		return;
	}

	chosp(linkto);

	if(is_dir(linkto) && !follow_dirs)
	{
		dir = strdup(entry->name);
		file = NULL;
	}
	else
	{
		dir = strdup(linkto);
		remove_last_path_component(dir);

		file = get_last_path_component(linkto);
	}

	if(dir[0] != '\0')
	{
		navigate_to(view, dir);
	}

	if(file != NULL)
	{
		const int pos = find_file_pos_in_list(view, file);
		if(pos >= 0)
		{
			flist_set_pos(view, pos);
		}
	}

	free(dir);
}
Exemplo n.º 3
0
static void check_realpath(const char *path, int expected_errno)
{
	char buffer[PATH_MAX + 1], *resolved_path;
	int expected_errno2;
	struct stat statbuf[2];

	assert(path);

	/* any errors in the path that realpath should report? */
	expected_errno2 = check_path_components(path);
	
	/* run realpath */
	errno = 0;
	resolved_path = realpath(path, buffer);

	/* do we get errors when expected? */
	if (expected_errno || expected_errno2)
	{
		if (resolved_path) ERR;
		if (errno != expected_errno && errno != expected_errno2) ERR;
		return;
	}

	/* do we get success when expected? */
	if (!resolved_path)
	{
		ERR;
		return;
	}
	errno = 0;

	/* do the paths point to the same file? (only check if exists) */
	if (stat(path,          &statbuf[0]) < 0) 
	{
		if (errno != ENOENT) { ERR; return; }
	}
	else
	{
		if (stat(resolved_path, &statbuf[1]) < 0) { ERR; return; }
		if (statbuf[0].st_dev != statbuf[1].st_dev) ERR;
		if (statbuf[0].st_ino != statbuf[1].st_ino) ERR;
	}

	/* is the path absolute? */
	if (resolved_path[0] != '/') ERR;

	/* is each path element allowable? */
	while (remove_last_path_component(resolved_path))
	{
		/* not a symlink? */
		if (lstat(resolved_path, &statbuf[1]) < 0) { ERR; return; }
		if ((statbuf[1].st_mode & S_IFMT) != S_IFDIR) ERR;
	}
}
Exemplo n.º 4
0
Arquivo: fuse.c Projeto: jubalh/vifm
/* Adds new entry to the list of *mounts. */
static void
register_mount(fuse_mount_t **mounts, const char file_full_path[],
		const char mount_point[], int id)
{
	fuse_mount_t *fuse_mount = malloc(sizeof(*fuse_mount));

	copy_str(fuse_mount->source_file_name, sizeof(fuse_mount->source_file_name),
			file_full_path);

	copy_str(fuse_mount->source_file_dir, sizeof(fuse_mount->source_file_dir),
			file_full_path);
	remove_last_path_component(fuse_mount->source_file_dir);

	canonicalize_path(mount_point, fuse_mount->mount_point,
			sizeof(fuse_mount->mount_point));

	fuse_mount->mount_point_id = id;

	fuse_mount->next = *mounts;
	*mounts = fuse_mount;
}
Exemplo n.º 5
0
int
compare_move(FileView *from, FileView *to)
{
	char from_path[PATH_MAX], to_path[PATH_MAX];
	char *from_fingerprint, *to_fingerprint;

	const CompareType ct = from->custom.diff_cmp_type;

	dir_entry_t *const curr = &from->dir_entry[from->list_pos];
	dir_entry_t *const other = &to->dir_entry[from->list_pos];

	if(from->custom.type != CV_DIFF || !from->custom.diff_path_group)
	{
		status_bar_error("Not in diff mode with path grouping");
		return 1;
	}

	if(curr->id == other->id && !fentry_is_fake(curr) && !fentry_is_fake(other))
	{
		/* Nothing to do if files are already equal. */
		return 0;
	}

	/* We're going at least to try to update one of views (which might refer to
	 * the same directory), so schedule a reload. */
	ui_view_schedule_reload(from);
	ui_view_schedule_reload(to);

	if(fentry_is_fake(curr))
	{
		/* Just remove the other file (it can't be fake entry too). */
		return fops_delete_current(to, 1, 0);
	}

	get_full_path_of(curr, sizeof(from_path), from_path);
	get_full_path_of(other, sizeof(to_path), to_path);

	if(fentry_is_fake(other))
	{
		char to_path[PATH_MAX];
		char canonical[PATH_MAX];
		snprintf(to_path, sizeof(to_path), "%s/%s/%s", flist_get_dir(to),
				curr->origin + strlen(flist_get_dir(from)), curr->name);
		canonicalize_path(to_path, canonical, sizeof(canonical));

		/* Copy current file to position of the other one using relative path with
		 * different base. */
		fops_replace(from, canonical, 0);

		/* Update the other entry to not be fake. */
		remove_last_path_component(canonical);
		replace_string(&other->name, curr->name);
		replace_string(&other->origin, canonical);
	}
	else
	{
		/* Overwrite file in the other pane with corresponding file from current
		 * pane. */
		fops_replace(from, to_path, 1);
	}

	/* Obtaining file fingerprint relies on size field of entries, so try to load
	 * it and ignore if it fails. */
	other->size = get_file_size(to_path);

	/* Try to update id of the other entry by computing fingerprint of both files
	 * and checking if they match. */

	from_fingerprint = get_file_fingerprint(from_path, curr, ct);
	to_fingerprint = get_file_fingerprint(to_path, other, ct);

	if(!is_null_or_empty(from_fingerprint) && !is_null_or_empty(to_fingerprint))
	{
		int match = (strcmp(from_fingerprint, to_fingerprint) == 0);
		if(match && ct == CT_CONTENTS)
		{
			match = files_are_identical(from_path, to_path);
		}
		if(match)
		{
			other->id = curr->id;
		}
	}

	free(from_fingerprint);
	free(to_fingerprint);

	return 0;
}
Exemplo n.º 6
0
void
exclude_file_name(char *path)
{
	if(path_exists(path) && !is_valid_dir(path))
		remove_last_path_component(path);
}