tweaks: check in a single place for files that should not be opened
Этот коммит содержится в:
родитель
6a83bb7508
Коммит
f6e182ca72
24
src/files.c
24
src/files.c
@ -411,6 +411,7 @@ bool open_buffer(const char *filename, bool new_buffer)
|
||||
{
|
||||
char *realname;
|
||||
/* The filename after tilde expansion. */
|
||||
struct stat fileinfo;
|
||||
FILE *f;
|
||||
int rc;
|
||||
/* rc == -2 means that we have a new file. -1 means that the
|
||||
@ -429,15 +430,18 @@ bool open_buffer(const char *filename, bool new_buffer)
|
||||
|
||||
realname = real_dir_from_tilde(filename);
|
||||
|
||||
/* When the given filename refers to a directory, don't try to open it. */
|
||||
if (*filename != '\0') {
|
||||
struct stat fileinfo;
|
||||
|
||||
if (stat(realname, &fileinfo) == 0 && S_ISDIR(fileinfo.st_mode)) {
|
||||
/* Don't try to open directories, character files, or block files. */
|
||||
if (*filename != '\0' && stat(realname, &fileinfo) == 0) {
|
||||
if (S_ISDIR(fileinfo.st_mode)) {
|
||||
statusline(ALERT, _("\"%s\" is a directory"), realname);
|
||||
free(realname);
|
||||
return FALSE;
|
||||
}
|
||||
if (S_ISCHR(fileinfo.st_mode) || S_ISBLK(fileinfo.st_mode)) {
|
||||
statusline(ALERT, _("\"%s\" is a device file"), realname);
|
||||
free(realname);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we're going to load into a new buffer, first create the new
|
||||
@ -929,16 +933,6 @@ int open_file(const char *filename, bool newfie, FILE **f)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Don't open directories, character files, or block files. */
|
||||
if (S_ISDIR(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) ||
|
||||
S_ISBLK(fileinfo.st_mode)) {
|
||||
statusline(ALERT, S_ISDIR(fileinfo.st_mode) ?
|
||||
_("\"%s\" is a directory") :
|
||||
_("\"%s\" is a device file"), filename);
|
||||
free(full_filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (S_ISFIFO(fileinfo.st_mode))
|
||||
statusbar(_("Reading from FIFO..."));
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user