fix filename space related issues
This commit is contained in:
parent
6bc1cdf536
commit
3d34b453dd
@ -290,7 +290,7 @@ int execute_directive_file(FILE * f) {
|
||||
|
||||
// Name (move)
|
||||
if (!entry->is_mentioned) {
|
||||
CHECK_FORMAT(1, sscanf(sp, "%s\n", buffer));
|
||||
CHECK_FORMAT(1, sscanf(sp, "%[^\n]", buffer));
|
||||
size_t len = strlen(buffer);
|
||||
if (buffer[len-1] == '/') {
|
||||
buffer[len-1] = '\0';
|
||||
|
@ -227,10 +227,15 @@ int moist_delete(const char * filename) {
|
||||
if (access(filename, F_OK)) { return 0; }
|
||||
|
||||
if (custom_rm) {
|
||||
size_t cmd_len = strlen(custom_rm) + sizeof(' ') + strlen(filename) + 1;
|
||||
size_t cmd_len = strlen(custom_rm)
|
||||
+ sizeof(' ')
|
||||
+ sizeof('\'')*2
|
||||
+ strlen(filename)
|
||||
+ 1
|
||||
;
|
||||
char cmd[cmd_len];
|
||||
|
||||
snprintf(cmd, cmd_len, "%s %s", custom_rm, filename);
|
||||
snprintf(cmd, cmd_len, "%s '%s'", custom_rm, filename);
|
||||
|
||||
int result = system(cmd);
|
||||
if (result == 127
|
||||
@ -298,13 +303,13 @@ int moist_copy(const char * filename, const char * newname) {
|
||||
// Is using system for copying terrible? yes.
|
||||
// Do I have know a better solution thats not filled with footguns? no.
|
||||
size_t cmd_len = strlen("cp -a")
|
||||
+ sizeof(' ') + strlen(filename)
|
||||
+ sizeof(' ') + strlen(newname)
|
||||
+ sizeof(' ') + sizeof('\'')*2 + strlen(filename)
|
||||
+ sizeof(' ') + sizeof('\'')*2 + strlen(newname)
|
||||
+ 1
|
||||
;
|
||||
char cmd[cmd_len];
|
||||
|
||||
snprintf(cmd, cmd_len, "cp -a %s %s", filename, newname);
|
||||
snprintf(cmd, cmd_len, "cp -a '%s' '%s'", filename, newname);
|
||||
|
||||
int result = system(cmd);
|
||||
if (result == 127
|
||||
|
@ -465,3 +465,52 @@ class CMDTEST_myswapdir < Cmdtest::Testcase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
# ___ _ _
|
||||
# / __|_ __ __ _ __ ___ __| (_)_ _
|
||||
# \__ \ '_ \/ _` / _/ -_) _` | | '_|
|
||||
# |___/ .__/\__,_\__\___\__,_|_|_|
|
||||
# |_|
|
||||
class CMDTEST_myswapdir < Cmdtest::Testcase
|
||||
def setup
|
||||
import_file "test/replacer.sh", "./"
|
||||
import_file "test/saver.sh", "./"
|
||||
import_directory "test/myspacedir/", "./myspacedir/"
|
||||
end
|
||||
|
||||
def test_space_contents
|
||||
expected = [
|
||||
"000\t./myspacedir/laptop/",
|
||||
"001\t./myspacedir/laptop/with a spacebar",
|
||||
"002\t./myspacedir/my space.txt",
|
||||
"003\t./myspacedir/space bar/",
|
||||
"004\t./myspacedir/space bar/wine",
|
||||
]
|
||||
|
||||
cmd "EDITOR=./saver.sh vimdir -n -r ./myspacedir/" do
|
||||
exit_zero
|
||||
created_files ["output.txt"]
|
||||
file_equal "output.txt", expected
|
||||
end
|
||||
end
|
||||
|
||||
def test_space_copy
|
||||
File.write('target.txt',
|
||||
[
|
||||
"000\t./myspacedir/laptop/",
|
||||
"001\t./myspacedir/laptop/with a spacebar",
|
||||
"002\t./myspacedir/my space.txt",
|
||||
"002\t./myspacedir/myspace.txt",
|
||||
"003\t./myspacedir/space bar/",
|
||||
"004\t./myspacedir/space bar/wine",
|
||||
].join("\n")
|
||||
)
|
||||
|
||||
cmd "EDITOR=./replacer.sh vimdir -r ./myspacedir/" do
|
||||
exit_zero
|
||||
created_files ["myspacedir/myspace.txt"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
0
test/myspacedir/laptop/with a spacebar
Normal file
0
test/myspacedir/laptop/with a spacebar
Normal file
1
test/myspacedir/my space.txt
Normal file
1
test/myspacedir/my space.txt
Normal file
@ -0,0 +1 @@
|
||||
wait, that still exists?
|
0
test/myspacedir/space bar/wine
Normal file
0
test/myspacedir/space bar/wine
Normal file
Loading…
x
Reference in New Issue
Block a user