implement custom deletion
This commit is contained in:
parent
e4a39962b1
commit
a2a5aacf63
@ -109,6 +109,6 @@ its (changed) value is ignored.
|
||||
- [X] change owner
|
||||
- [ ] swapping
|
||||
- [ ] copying
|
||||
- [ ] specify the deletion method (so trash can be supported)
|
||||
- [X] specify the deletion method (so trash can be supported)
|
||||
- [X] use `${VIMDIREDITOR}`
|
||||
- [X] `NO_COLOR` / color
|
||||
|
@ -19,6 +19,8 @@ extern char * trim_trailing_slashes(char * path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
static const char * custom_rm = NULL;
|
||||
|
||||
int (*mytouch)(const char *filename) = NULL;
|
||||
int (*mydelete)(const char *filename) = NULL;
|
||||
int (*mychmod)(const char *filename, mode_t mode) = NULL;
|
||||
@ -36,8 +38,9 @@ static int moist_delete(const char * filename);
|
||||
static int moist_chmod(const char * filename, mode_t mode);
|
||||
static int moist_chown(const char * filename, const char * owner, const char * group);
|
||||
static int moist_move(const char * filename, const char * newname);
|
||||
int init_file_utils(bool is_dry_run, const char * custom_rm_) {
|
||||
custom_rm = custom_rm_;
|
||||
|
||||
int init_file_utils(bool is_dry_run) {
|
||||
if (is_dry_run) {
|
||||
mytouch = dry_touch;
|
||||
mydelete = dry_delete;
|
||||
@ -62,6 +65,8 @@ int deinit_file_utis() {
|
||||
mychown = NULL;
|
||||
mymove = NULL;
|
||||
|
||||
custom_rm = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -173,9 +178,24 @@ int moist_touch(const char * filename) {
|
||||
|
||||
static
|
||||
int moist_delete(const char * filename) {
|
||||
if (unlink(filename) != 0) {
|
||||
errorn(E_FILE_DELETE, filename);
|
||||
return 1;
|
||||
if (custom_rm) {
|
||||
size_t cmd_len = strlen(custom_rm) + sizeof(' ') + strlen(filename) + 1;
|
||||
char cmd[cmd_len];
|
||||
|
||||
snprintf(cmd, cmd_len, "%s %s", custom_rm, filename);
|
||||
|
||||
int result = system(cmd);
|
||||
if (result == 127
|
||||
|| result == -1
|
||||
|| (WIFEXITED(result) && WEXITSTATUS(result) != 0)) {
|
||||
errorn(E_FILE_DELETE, filename);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
//if (unlink(filename) != 0) {
|
||||
// errorn(E_FILE_DELETE, filename);
|
||||
// return 1;
|
||||
//}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
extern int init_file_utils(bool is_dry_run);
|
||||
extern int init_file_utils(bool is_dry_run, const char * custom_rm_);
|
||||
extern int deinit_file_utis();
|
||||
|
||||
extern char * trim_trailing_slashes(char * path);
|
||||
|
@ -66,6 +66,7 @@ class CMDTEST_mydir < Cmdtest::Testcase
|
||||
import_file "test/replacer.sh", "./"
|
||||
import_file "test/saver.sh", "./"
|
||||
import_file "test/memoryhole.sh", "./"
|
||||
import_file "test/trash.sh", "./"
|
||||
import_directory "test/mydir/", "./mydir/"
|
||||
end
|
||||
|
||||
@ -152,6 +153,21 @@ class CMDTEST_mydir < Cmdtest::Testcase
|
||||
end
|
||||
end
|
||||
|
||||
def test_del_custom
|
||||
File.write('target.txt',
|
||||
[
|
||||
"000\t./mydir/.gitkeep",
|
||||
"002\t./mydir/script.sh"
|
||||
].join("\n")
|
||||
)
|
||||
|
||||
cmd "VIMDIRRM=./trash.sh EDITOR=./replacer.sh vimdir ./mydir/" do
|
||||
exit_zero
|
||||
created_files ["vimdir_test_file.vimdir", "mydir/file.txt.trash"]
|
||||
removed_files ["target.txt", "mydir/file.txt"]
|
||||
end
|
||||
end
|
||||
|
||||
def test_swapped_order_noop
|
||||
File.write('target.txt',
|
||||
[
|
||||
|
2
test/trash.sh
Executable file
2
test/trash.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
mv $1 $1.trash
|
Loading…
x
Reference in New Issue
Block a user