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.
Commit fda5f5dc7b3facb3fdaa8de637bd81198b5658f7

Fix C key not checking readability of a file
When it is a single unselected file. :clone does the right thing in
this case.
Author: xaizek
Author date (UTC): 2018-01-28 15:55
Committer name: xaizek
Committer date (UTC): 2018-01-29 11:09
Parent(s): c5f3821f5c99956f4c9edcbaa7a42e5016991fcb
Signing key: 99DC5E4DB05F6BE2
Tree: 87a43c8edbb2f68e0ac68ebead664fcdad2281a7
File Lines added Lines deleted
ChangeLog 3 0
src/fops_common.c 2 2
src/fops_common.h 3 3
src/fops_cpmv.c 1 1
src/fops_misc.c 1 1
tests/fileops/clone_files.c 16 0
tests/fileops/cpmv_files.c 16 0
File ChangeLog changed (mode: 100644) (index 49e7e7af1..adb9ae79f)
3 3 Fixed :clone and :copy refusing to copy broken symbolic links, even though C Fixed :clone and :copy refusing to copy broken symbolic links, even though C
4 4 and p keys copy them. and p keys copy them.
5 5
6 Fixed C key not checking readability of a single unselected file, like
7 :clone does.
8
6 9 0.9 to 0.9.1-beta 0.9 to 0.9.1-beta
7 10
8 11 Added "inode" sorting key, which sorts entries by inode number. Thanks to Added "inode" sorting key, which sorts entries by inode number. Thanks to
File src/fops_common.c changed (mode: 100644) (index 95b6218c7..ec234a29c)
... ... fops_get_dst_name(const char src_path[], int from_trash)
675 675 } }
676 676
677 677 int int
678 fops_can_read_selected_files(view_t *view)
678 fops_can_read_marked_files(view_t *view)
679 679 { {
680 680 dir_entry_t *entry; dir_entry_t *entry;
681 681
 
... ... fops_can_read_selected_files(view_t *view)
685 685 } }
686 686
687 687 entry = NULL; entry = NULL;
688 while(iter_selected_entries(view, &entry))
688 while(iter_marked_entries(view, &entry))
689 689 { {
690 690 char full_path[PATH_MAX + 1]; char full_path[PATH_MAX + 1];
691 691 get_full_path_of(entry, sizeof(full_path), full_path); get_full_path_of(entry, sizeof(full_path), full_path);
File src/fops_common.h changed (mode: 100644) (index 20c6cb522..3fb1063a0)
... ... void fops_progress_msg(const char text[], int ready, int total);
133 133 * name. */ * name. */
134 134 const char * fops_get_dst_name(const char src_path[], int from_trash); const char * fops_get_dst_name(const char src_path[], int from_trash);
135 135
136 /* Checks that all selected files can be read. Returns non-zero if so,
137 * otherwise zero is returned. */
138 int fops_can_read_selected_files(struct view_t *view);
136 /* Checks that all marked files can be read. Returns non-zero if so, otherwise
137 * zero is returned. */
138 int fops_can_read_marked_files(struct view_t *view);
139 139
140 140 /* Checks path argument and resolves target directory either to the argument or /* Checks path argument and resolves target directory either to the argument or
141 141 * current directory of the view. Returns non-zero if value of the path was * current directory of the view. Returns non-zero if value of the path was
File src/fops_cpmv.c changed (mode: 100644) (index 55d88444e..a9a554d16)
... ... cpmv_prepare(view_t *view, char ***list, int *nlines, CopyMoveLikeOp op,
338 338 return -1; return -1;
339 339 } }
340 340 } }
341 else if(op == CMLO_COPY && !fops_can_read_selected_files(view))
341 else if(op == CMLO_COPY && !fops_can_read_marked_files(view))
342 342 { {
343 343 return -1; return -1;
344 344 } }
File src/fops_misc.c changed (mode: 100644) (index 59bc1fdd2..324c2b602)
... ... fops_clone(view_t *view, char *list[], int nlines, int force, int copies)
594 594 ops_t *ops; ops_t *ops;
595 595 const char *const curr_dir = flist_get_dir(view); const char *const curr_dir = flist_get_dir(view);
596 596
597 if(!fops_can_read_selected_files(view))
597 if(!fops_can_read_marked_files(view))
598 598 { {
599 599 return 0; return 0;
600 600 } }
File tests/fileops/clone_files.c changed (mode: 100644) (index 935ccb536..83200e072)
1 1 #include <stic.h> #include <stic.h>
2 2
3 #include <sys/stat.h> /* chmod() */
3 4 #include <unistd.h> /* chdir() symlink() unlink() */ #include <unistd.h> /* chdir() symlink() unlink() */
4 5
5 6 #include "../../src/cfg/config.h" #include "../../src/cfg/config.h"
 
... ... TEST(cloning_of_broken_symlink, IF(not_windows))
154 155 assert_success(unlink("broken-link")); assert_success(unlink("broken-link"));
155 156 } }
156 157
158 TEST(cloning_is_aborted_if_we_can_not_read_a_file, IF(not_windows))
159 {
160 create_empty_file("can-read");
161 create_empty_file("can-not-read");
162 assert_success(chmod("can-not-read", 0000));
163 populate_dir_list(&lwin, 0);
164
165 lwin.dir_entry[0].marked = 1;
166 lwin.dir_entry[1].marked = 1;
167 assert_int_equal(0, fops_clone(&lwin, NULL, 0, 0, 1));
168
169 assert_success(unlink("can-read"));
170 assert_success(unlink("can-not-read"));
171 }
172
157 173 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
158 174 /* vim: set cinoptions+=t0 : */ /* vim: set cinoptions+=t0 : */
File tests/fileops/cpmv_files.c changed (mode: 100644) (index 9df901a8d..fb269ac2c)
1 1 #include <stic.h> #include <stic.h>
2 2
3 #include <sys/stat.h> /* chmod() */
3 4 #include <unistd.h> /* chdir() unlink() */ #include <unistd.h> /* chdir() unlink() */
4 5
5 6 #include <stddef.h> /* NULL */ #include <stddef.h> /* NULL */
 
... ... TEST(parent_overwrite_is_prevented_on_file_move)
311 312 check_directory_clash(0, CMLO_MOVE); check_directory_clash(0, CMLO_MOVE);
312 313 } }
313 314
315 TEST(copying_is_aborted_if_we_can_not_read_a_file, IF(not_windows))
316 {
317 create_empty_file("can-read");
318 create_empty_file("can-not-read");
319 assert_success(chmod("can-not-read", 0000));
320 populate_dir_list(&lwin, 0);
321
322 lwin.dir_entry[0].marked = 1;
323 lwin.dir_entry[1].marked = 1;
324 assert_int_equal(0, fops_cpmv(&lwin, NULL, 0, CMLO_COPY, 0));
325
326 assert_success(unlink("can-read"));
327 assert_success(unlink("can-not-read"));
328 }
329
314 330 static void static void
315 331 check_directory_clash(int parent_to_child, CopyMoveLikeOp op) check_directory_clash(int parent_to_child, CopyMoveLikeOp op)
316 332 { {
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