File src/cfg/config.c changed (mode: 100644) (index e7f127807..eee262ea2) |
29 |
29 |
#define CP_RC "cp " PACKAGE_DATA_DIR "/" VIFMRC " ~/.vifm" |
#define CP_RC "cp " PACKAGE_DATA_DIR "/" VIFMRC " ~/.vifm" |
30 |
30 |
#endif |
#endif |
31 |
31 |
|
|
|
32 |
|
#include <assert.h> /* assert() */ |
32 |
33 |
#include <errno.h> |
#include <errno.h> |
33 |
34 |
#include <limits.h> /* INT_MIN PATH_MAX */ |
#include <limits.h> /* INT_MIN PATH_MAX */ |
34 |
|
#include <stdio.h> /* FILE */ |
|
|
35 |
|
#include <stdio.h> /* FILE snprintf() */ |
35 |
36 |
#include <stdlib.h> |
#include <stdlib.h> |
36 |
|
#include <string.h> /* memset() */ |
|
|
37 |
|
#include <string.h> /* memset() strncpy() */ |
37 |
38 |
|
|
38 |
39 |
#include "../menus/menus.h" |
#include "../menus/menus.h" |
39 |
40 |
#include "../utils/env.h" |
#include "../utils/env.h" |
|
... |
... |
static void create_rc_file(void); |
81 |
82 |
#endif |
#endif |
82 |
83 |
static void add_default_bookmarks(void); |
static void add_default_bookmarks(void); |
83 |
84 |
static int source_file_internal(FILE *fp, const char filename[]); |
static int source_file_internal(FILE *fp, const char filename[]); |
|
85 |
|
static const char * get_tmpdir(void); |
84 |
86 |
static void free_view_history(FileView *view); |
static void free_view_history(FileView *view); |
85 |
87 |
static void reduce_view_history(FileView *view, size_t size); |
static void reduce_view_history(FileView *view, size_t size); |
86 |
88 |
|
|
|
... |
... |
init_config(void) |
116 |
118 |
cfg.vi_x_command = strdup(""); |
cfg.vi_x_command = strdup(""); |
117 |
119 |
cfg.vi_x_cmd_bg = 0; |
cfg.vi_x_cmd_bg = 0; |
118 |
120 |
cfg.use_trash = 1; |
cfg.use_trash = 1; |
119 |
|
cfg.fuse_home = strdup("/tmp/vifm_FUSE"); |
|
|
121 |
|
|
|
122 |
|
cfg.fuse_home = format_str("%s/vifm_FUSE", get_tmpdir()); |
|
123 |
|
assert(cfg.fuse_home != NULL); |
|
124 |
|
#ifdef _WIN32 |
|
125 |
|
to_forward_slash(cfg.fuse_home); |
|
126 |
|
#endif |
|
127 |
|
|
120 |
128 |
cfg.use_screen = 0; |
cfg.use_screen = 0; |
121 |
129 |
cfg.use_vim_help = 0; |
cfg.use_vim_help = 0; |
122 |
130 |
cfg.wild_menu = 0; |
cfg.wild_menu = 0; |
|
... |
... |
get_vicmd(int *bg) |
629 |
637 |
} |
} |
630 |
638 |
} |
} |
631 |
639 |
|
|
|
640 |
|
void |
|
641 |
|
generate_tmp_file_name(const char prefix[], char buf[], size_t buf_len) |
|
642 |
|
{ |
|
643 |
|
snprintf(buf, buf_len, "%s/%s", get_tmpdir(), prefix); |
|
644 |
|
#ifdef _WIN32 |
|
645 |
|
to_forward_slash(buf); |
|
646 |
|
#endif |
|
647 |
|
strncpy(buf, make_name_unique(buf), buf_len); |
|
648 |
|
} |
|
649 |
|
|
|
650 |
|
/* Returns path to tmp directory. Uses environment variables to determine the |
|
651 |
|
* correct place. */ |
|
652 |
|
const char * |
|
653 |
|
get_tmpdir(void) |
|
654 |
|
{ |
|
655 |
|
return env_get_one_of_def("/tmp/", "TMPDIR", "TEMP", "TEMPDIR", "TMP", NULL); |
|
656 |
|
} |
|
657 |
|
|
632 |
658 |
void |
void |
633 |
659 |
resize_history(size_t new_len) |
resize_history(size_t new_len) |
634 |
660 |
{ |
{ |
File src/cfg/config.h changed (mode: 100644) (index 437c8e4d6..3c2f50936) |
22 |
22 |
|
|
23 |
23 |
#include <curses.h> |
#include <curses.h> |
24 |
24 |
|
|
|
25 |
|
#include <stddef.h> /* size_t */ |
25 |
26 |
#include <limits.h> /* PATH_MAX */ |
#include <limits.h> /* PATH_MAX */ |
26 |
27 |
|
|
27 |
28 |
#include "../color_scheme.h" |
#include "../color_scheme.h" |
|
... |
... |
int source_file(const char filename[]); |
124 |
125 |
int is_old_config(void); |
int is_old_config(void); |
125 |
126 |
int are_old_color_schemes(void); |
int are_old_color_schemes(void); |
126 |
127 |
const char * get_vicmd(int *bg); |
const char * get_vicmd(int *bg); |
|
128 |
|
/* Generates name of file inside tmp folder. */ |
|
129 |
|
void generate_tmp_file_name(const char prefix[], char buf[], size_t buf_len); |
127 |
130 |
void create_trash_dir(void); |
void create_trash_dir(void); |
128 |
131 |
/* Changes size of all histories. */ |
/* Changes size of all histories. */ |
129 |
132 |
void resize_history(size_t new_len); |
void resize_history(size_t new_len); |
File src/fileops.c changed (mode: 100644) (index 215b77dab..6bf89354c) |
... |
... |
perform_renaming(FileView *view, char **files, int *is_dup, int len, |
729 |
729 |
return renamed; |
return renamed; |
730 |
730 |
} |
} |
731 |
731 |
|
|
732 |
|
#ifdef _WIN32 |
|
733 |
|
static void |
|
734 |
|
change_slashes(char *str) |
|
735 |
|
{ |
|
736 |
|
int i; |
|
737 |
|
for(i = 0; str[i] != '\0'; i++) |
|
738 |
|
{ |
|
739 |
|
if(str[i] == '\\') |
|
740 |
|
str[i] = '/'; |
|
741 |
|
} |
|
742 |
|
} |
|
743 |
|
#endif |
|
744 |
|
|
|
745 |
732 |
static char ** |
static char ** |
746 |
733 |
read_list_from_file(int count, char **names, int *nlines, int require_change) |
read_list_from_file(int count, char **names, int *nlines, int require_change) |
747 |
734 |
{ |
{ |
748 |
|
char temp_file[PATH_MAX]; |
|
|
735 |
|
char rename_file[PATH_MAX]; |
749 |
736 |
char **list; |
char **list; |
750 |
737 |
FILE *f; |
FILE *f; |
751 |
738 |
int i; |
int i; |
752 |
739 |
|
|
753 |
|
#ifndef _WIN32 |
|
754 |
|
snprintf(temp_file, sizeof(temp_file), "/tmp/vifm.rename"); |
|
755 |
|
#else |
|
756 |
|
snprintf(temp_file, sizeof(temp_file), "%s\\vifm.rename", env_get("TMP")); |
|
757 |
|
change_slashes(temp_file); |
|
758 |
|
#endif |
|
759 |
|
strncpy(temp_file, make_name_unique(temp_file), sizeof(temp_file)); |
|
|
740 |
|
generate_tmp_file_name("vifm.rename", rename_file, sizeof(rename_file)); |
760 |
741 |
|
|
761 |
|
if((f = fopen(temp_file, "w")) == NULL) |
|
|
742 |
|
if((f = fopen(rename_file, "w")) == NULL) |
762 |
743 |
{ |
{ |
763 |
744 |
status_bar_error("Can't create temp file"); |
status_bar_error("Can't create temp file"); |
764 |
745 |
curr_stats.save_msg = 1; |
curr_stats.save_msg = 1; |
|
... |
... |
read_list_from_file(int count, char **names, int *nlines, int require_change) |
774 |
755 |
{ |
{ |
775 |
756 |
struct stat st_before, st_after; |
struct stat st_before, st_after; |
776 |
757 |
|
|
777 |
|
stat(temp_file, &st_before); |
|
|
758 |
|
stat(rename_file, &st_before); |
778 |
759 |
|
|
779 |
|
view_file(temp_file, -1, 0); |
|
|
760 |
|
view_file(rename_file, -1, 0); |
780 |
761 |
|
|
781 |
|
stat(temp_file, &st_after); |
|
|
762 |
|
stat(rename_file, &st_after); |
782 |
763 |
|
|
783 |
764 |
if(memcmp(&st_after.st_mtime, &st_before.st_mtime, |
if(memcmp(&st_after.st_mtime, &st_before.st_mtime, |
784 |
765 |
sizeof(st_after.st_mtime)) == 0) |
sizeof(st_after.st_mtime)) == 0) |
785 |
766 |
{ |
{ |
786 |
|
unlink(temp_file); |
|
|
767 |
|
unlink(rename_file); |
787 |
768 |
curr_stats.save_msg = 0; |
curr_stats.save_msg = 0; |
788 |
769 |
return NULL; |
return NULL; |
789 |
770 |
} |
} |
790 |
771 |
} |
} |
791 |
772 |
else |
else |
792 |
773 |
{ |
{ |
793 |
|
view_file(temp_file, -1, 0); |
|
|
774 |
|
view_file(rename_file, -1, 0); |
794 |
775 |
} |
} |
795 |
776 |
|
|
796 |
|
if((f = fopen(temp_file, "r")) == NULL) |
|
|
777 |
|
if((f = fopen(rename_file, "r")) == NULL) |
797 |
778 |
{ |
{ |
798 |
|
unlink(temp_file); |
|
|
779 |
|
unlink(rename_file); |
799 |
780 |
status_bar_error("Can't open temporary file"); |
status_bar_error("Can't open temporary file"); |
800 |
781 |
curr_stats.save_msg = 1; |
curr_stats.save_msg = 1; |
801 |
782 |
return NULL; |
return NULL; |
|
... |
... |
read_list_from_file(int count, char **names, int *nlines, int require_change) |
803 |
784 |
|
|
804 |
785 |
list = read_file_lines(f, nlines); |
list = read_file_lines(f, nlines); |
805 |
786 |
fclose(f); |
fclose(f); |
806 |
|
unlink(temp_file); |
|
|
787 |
|
unlink(rename_file); |
807 |
788 |
|
|
808 |
789 |
curr_stats.save_msg = 0; |
curr_stats.save_msg = 0; |
809 |
790 |
return list; |
return list; |
File src/fuse.c changed (mode: 100644) (index 54923c6ae..e0f2721cd) |
... |
... |
fuse_mount(FileView *view, char *file_full_path, const char *param, |
159 |
159 |
char buf[2*PATH_MAX]; |
char buf[2*PATH_MAX]; |
160 |
160 |
char *escaped_filename; |
char *escaped_filename; |
161 |
161 |
int clear_before_mount = 0; |
int clear_before_mount = 0; |
162 |
|
const char *tmp_file; |
|
|
162 |
|
char errors_file[PATH_MAX]; |
163 |
163 |
int status; |
int status; |
164 |
164 |
|
|
165 |
165 |
escaped_filename = escape_filename(get_current_file_name(view), 0); |
escaped_filename = escape_filename(get_current_file_name(view), 0); |
|
... |
... |
fuse_mount(FileView *view, char *file_full_path, const char *param, |
209 |
209 |
endwin(); |
endwin(); |
210 |
210 |
} |
} |
211 |
211 |
|
|
212 |
|
tmp_file = make_name_unique("/tmp/vifm.errors"); |
|
|
212 |
|
generate_tmp_file_name("vifm.errors", errors_file, sizeof(errors_file)); |
|
213 |
|
|
213 |
214 |
strcat(buf, " 2> "); |
strcat(buf, " 2> "); |
214 |
|
strcat(buf, tmp_file); |
|
|
215 |
|
strcat(buf, errors_file); |
215 |
216 |
LOG_INFO_MSG("FUSE mount command: `%s`", buf); |
LOG_INFO_MSG("FUSE mount command: `%s`", buf); |
216 |
217 |
status = background_and_wait_for_status(buf); |
status = background_and_wait_for_status(buf); |
217 |
218 |
|
|
|
... |
... |
fuse_mount(FileView *view, char *file_full_path, const char *param, |
220 |
221 |
/* check child status */ |
/* check child status */ |
221 |
222 |
if(!WIFEXITED(status) || (WIFEXITED(status) && WEXITSTATUS(status))) |
if(!WIFEXITED(status) || (WIFEXITED(status) && WEXITSTATUS(status))) |
222 |
223 |
{ |
{ |
223 |
|
FILE *ef = fopen(tmp_file, "r"); |
|
|
224 |
|
FILE *ef = fopen(errors_file, "r"); |
224 |
225 |
print_errors(ef); |
print_errors(ef); |
225 |
|
unlink(tmp_file); |
|
|
226 |
|
unlink(errors_file); |
226 |
227 |
|
|
227 |
228 |
werase(status_bar); |
werase(status_bar); |
228 |
229 |
/* remove the directory we created for the mount */ |
/* remove the directory we created for the mount */ |
|
... |
... |
fuse_mount(FileView *view, char *file_full_path, const char *param, |
232 |
233 |
(void)my_chdir(view->curr_dir); |
(void)my_chdir(view->curr_dir); |
233 |
234 |
return -1; |
return -1; |
234 |
235 |
} |
} |
235 |
|
unlink(tmp_file); |
|
|
236 |
|
unlink(errors_file); |
236 |
237 |
status_bar_message("FUSE mount success"); |
status_bar_message("FUSE mount success"); |
237 |
238 |
|
|
238 |
239 |
fuse_item = (fuse_mount_t *)malloc(sizeof(fuse_mount_t)); |
fuse_item = (fuse_mount_t *)malloc(sizeof(fuse_mount_t)); |