mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
replaced some mch_stat() with os_get_file_info()
This commit is contained in:
parent
a080819c3e
commit
902ad8d94d
13
src/eval.c
13
src/eval.c
@ -9713,15 +9713,14 @@ static void f_getfsize(typval_T *argvars, typval_T *rettv)
|
|||||||
*/
|
*/
|
||||||
static void f_getftime(typval_T *argvars, typval_T *rettv)
|
static void f_getftime(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
char_u *fname;
|
char *fname = (char *)get_tv_string(&argvars[0]);
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
fname = get_tv_string(&argvars[0]);
|
FileInfo file_info;
|
||||||
|
if (os_get_file_info(fname, &file_info)) {
|
||||||
if (mch_stat((char *)fname, &st) >= 0)
|
rettv->vval.v_number = (varnumber_T)file_info.stat.st_mtim.tv_sec;
|
||||||
rettv->vval.v_number = (varnumber_T)st.st_mtime;
|
} else {
|
||||||
else
|
|
||||||
rettv->vval.v_number = -1;
|
rettv->vval.v_number = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1496,9 +1496,6 @@ void write_viminfo(char_u *file, int forceit)
|
|||||||
#if defined(UNIX)
|
#if defined(UNIX)
|
||||||
mode_t umask_save;
|
mode_t umask_save;
|
||||||
#endif
|
#endif
|
||||||
#ifdef UNIX
|
|
||||||
struct stat st_old; /* mch_stat() of existing viminfo file */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (no_viminfo())
|
if (no_viminfo())
|
||||||
return;
|
return;
|
||||||
@ -1535,16 +1532,15 @@ void write_viminfo(char_u *file, int forceit)
|
|||||||
* overwrite a user's viminfo file after a "su root", with a
|
* overwrite a user's viminfo file after a "su root", with a
|
||||||
* viminfo file that the user can't read.
|
* viminfo file that the user can't read.
|
||||||
*/
|
*/
|
||||||
st_old.st_dev = (dev_t)0;
|
|
||||||
st_old.st_ino = 0;
|
FileInfo old_info; // FileInfo of existing viminfo file
|
||||||
st_old.st_mode = 0600;
|
if (os_get_file_info((char *)fname, &old_info)
|
||||||
if (mch_stat((char *)fname, &st_old) == 0
|
|
||||||
&& getuid() != ROOT_UID
|
&& getuid() != ROOT_UID
|
||||||
&& !(st_old.st_uid == getuid()
|
&& !(old_info.stat.st_uid == getuid()
|
||||||
? (st_old.st_mode & 0200)
|
? (old_info.stat.st_mode & 0200)
|
||||||
: (st_old.st_gid == getgid()
|
: (old_info.stat.st_gid == getgid()
|
||||||
? (st_old.st_mode & 0020)
|
? (old_info.stat.st_mode & 0020)
|
||||||
: (st_old.st_mode & 0002)))) {
|
: (old_info.stat.st_mode & 0002)))) {
|
||||||
int tt = msg_didany;
|
int tt = msg_didany;
|
||||||
|
|
||||||
/* avoid a wait_return for this message, it's annoying */
|
/* avoid a wait_return for this message, it's annoying */
|
||||||
@ -1596,7 +1592,7 @@ void write_viminfo(char_u *file, int forceit)
|
|||||||
umask_save = umask(0);
|
umask_save = umask(0);
|
||||||
fd = mch_open((char *)tempname,
|
fd = mch_open((char *)tempname,
|
||||||
O_CREAT|O_EXCL|O_WRONLY|O_NOFOLLOW,
|
O_CREAT|O_EXCL|O_WRONLY|O_NOFOLLOW,
|
||||||
(int)((st_old.st_mode & 0777) | 0600));
|
(int)((old_info.stat.st_mode & 0777) | 0600));
|
||||||
(void)umask(umask_save);
|
(void)umask(umask_save);
|
||||||
# else
|
# else
|
||||||
fd = mch_open((char *)tempname,
|
fd = mch_open((char *)tempname,
|
||||||
@ -1622,8 +1618,9 @@ void write_viminfo(char_u *file, int forceit)
|
|||||||
* Make sure the owner can read/write it. This only works for
|
* Make sure the owner can read/write it. This only works for
|
||||||
* root.
|
* root.
|
||||||
*/
|
*/
|
||||||
if (fp_out != NULL)
|
if (fp_out != NULL) {
|
||||||
ignored = fchown(fileno(fp_out), st_old.st_uid, st_old.st_gid);
|
fchown(fileno(fp_out), old_info.stat.st_uid, old_info.stat.st_gid);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,15 +48,13 @@
|
|||||||
static void cmd_source(char_u *fname, exarg_T *eap);
|
static void cmd_source(char_u *fname, exarg_T *eap);
|
||||||
|
|
||||||
/* Growarray to store info about already sourced scripts.
|
/* Growarray to store info about already sourced scripts.
|
||||||
* For Unix also store the dev/ino, so that we don't have to stat() each
|
* Also store the dev/ino, so that we don't have to stat() each
|
||||||
* script when going through the list. */
|
* script when going through the list. */
|
||||||
typedef struct scriptitem_S {
|
typedef struct scriptitem_S {
|
||||||
char_u *sn_name;
|
char_u *sn_name;
|
||||||
# ifdef UNIX
|
|
||||||
int sn_dev_valid;
|
int sn_dev_valid;
|
||||||
dev_t sn_dev;
|
uint64_t sn_dev;
|
||||||
ino_t sn_ino;
|
uint64_t sn_ino;
|
||||||
# endif
|
|
||||||
int sn_prof_on; /* TRUE when script is/was profiled */
|
int sn_prof_on; /* TRUE when script is/was profiled */
|
||||||
int sn_pr_force; /* forceit: profile functions in this script */
|
int sn_pr_force; /* forceit: profile functions in this script */
|
||||||
proftime_T sn_pr_child; /* time set when going into first child */
|
proftime_T sn_pr_child; /* time set when going into first child */
|
||||||
@ -2458,10 +2456,6 @@ do_source (
|
|||||||
void *save_funccalp;
|
void *save_funccalp;
|
||||||
int save_debug_break_level = debug_break_level;
|
int save_debug_break_level = debug_break_level;
|
||||||
scriptitem_T *si = NULL;
|
scriptitem_T *si = NULL;
|
||||||
# ifdef UNIX
|
|
||||||
struct stat st;
|
|
||||||
int stat_ok;
|
|
||||||
# endif
|
|
||||||
#ifdef STARTUPTIME
|
#ifdef STARTUPTIME
|
||||||
struct timeval tv_rel;
|
struct timeval tv_rel;
|
||||||
struct timeval tv_start;
|
struct timeval tv_start;
|
||||||
@ -2622,23 +2616,19 @@ do_source (
|
|||||||
* If it's new, generate a new SID.
|
* If it's new, generate a new SID.
|
||||||
*/
|
*/
|
||||||
save_current_SID = current_SID;
|
save_current_SID = current_SID;
|
||||||
# ifdef UNIX
|
FileInfo file_info;
|
||||||
stat_ok = (mch_stat((char *)fname_exp, &st) >= 0);
|
bool file_info_ok = os_get_file_info((char *)fname_exp, &file_info);
|
||||||
# endif
|
|
||||||
for (current_SID = script_items.ga_len; current_SID > 0; --current_SID) {
|
for (current_SID = script_items.ga_len; current_SID > 0; --current_SID) {
|
||||||
si = &SCRIPT_ITEM(current_SID);
|
si = &SCRIPT_ITEM(current_SID);
|
||||||
|
// Compare dev/ino when possible, it catches symbolic links.
|
||||||
|
// Also compare file names, the inode may change when the file was edited.
|
||||||
|
bool file_id_equal = file_info_ok && si->sn_dev_valid
|
||||||
|
&& si->sn_dev == file_info.stat.st_dev
|
||||||
|
&& si->sn_ino == file_info.stat.st_ino;
|
||||||
if (si->sn_name != NULL
|
if (si->sn_name != NULL
|
||||||
&& (
|
&& (file_id_equal || fnamecmp(si->sn_name, fname_exp) == 0)) {
|
||||||
# ifdef UNIX
|
|
||||||
/* Compare dev/ino when possible, it catches symbolic
|
|
||||||
* links. Also compare file names, the inode may change
|
|
||||||
* when the file was edited. */
|
|
||||||
((stat_ok && si->sn_dev_valid)
|
|
||||||
&& (si->sn_dev == st.st_dev
|
|
||||||
&& si->sn_ino == st.st_ino)) ||
|
|
||||||
# endif
|
|
||||||
fnamecmp(si->sn_name, fname_exp) == 0))
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (current_SID == 0) {
|
if (current_SID == 0) {
|
||||||
current_SID = ++last_current_SID;
|
current_SID = ++last_current_SID;
|
||||||
@ -2651,14 +2641,13 @@ do_source (
|
|||||||
si = &SCRIPT_ITEM(current_SID);
|
si = &SCRIPT_ITEM(current_SID);
|
||||||
si->sn_name = fname_exp;
|
si->sn_name = fname_exp;
|
||||||
fname_exp = NULL;
|
fname_exp = NULL;
|
||||||
# ifdef UNIX
|
if (file_info_ok) {
|
||||||
if (stat_ok) {
|
|
||||||
si->sn_dev_valid = TRUE;
|
si->sn_dev_valid = TRUE;
|
||||||
si->sn_dev = st.st_dev;
|
si->sn_dev = file_info.stat.st_dev;
|
||||||
si->sn_ino = st.st_ino;
|
si->sn_ino = file_info.stat.st_ino;
|
||||||
} else
|
} else {
|
||||||
si->sn_dev_valid = FALSE;
|
si->sn_dev_valid = FALSE;
|
||||||
# endif
|
}
|
||||||
|
|
||||||
/* Allocate the local script variables to use for this script. */
|
/* Allocate the local script variables to use for this script. */
|
||||||
new_script_vars(current_SID);
|
new_script_vars(current_SID);
|
||||||
|
@ -110,11 +110,9 @@ typedef struct ff_visited {
|
|||||||
/* for unix use inode etc for comparison (needed because of links), else
|
/* for unix use inode etc for comparison (needed because of links), else
|
||||||
* use filename.
|
* use filename.
|
||||||
*/
|
*/
|
||||||
#ifdef UNIX
|
|
||||||
int ffv_dev_valid; /* ffv_dev and ffv_ino were set */
|
int ffv_dev_valid; /* ffv_dev and ffv_ino were set */
|
||||||
dev_t ffv_dev; /* device number */
|
uint64_t ffv_dev; /* device number */
|
||||||
ino_t ffv_ino; /* inode number */
|
uint64_t ffv_ino; /* inode number */
|
||||||
#endif
|
|
||||||
/* The memory for this struct is allocated according to the length of
|
/* The memory for this struct is allocated according to the length of
|
||||||
* ffv_fname.
|
* ffv_fname.
|
||||||
*/
|
*/
|
||||||
@ -1126,38 +1124,27 @@ static int ff_wc_equal(char_u *s1, char_u *s2)
|
|||||||
static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *wc_path)
|
static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *wc_path)
|
||||||
{
|
{
|
||||||
ff_visited_T *vp;
|
ff_visited_T *vp;
|
||||||
#ifdef UNIX
|
bool url = false;
|
||||||
struct stat st;
|
|
||||||
int url = FALSE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* For an URL we only compare the name, otherwise we compare the
|
FileInfo file_info;
|
||||||
* device/inode (unix) or the full path name (not Unix). */
|
// For an URL we only compare the name, otherwise we compare the
|
||||||
|
// device/inode.
|
||||||
if (path_with_url(fname)) {
|
if (path_with_url(fname)) {
|
||||||
vim_strncpy(ff_expand_buffer, fname, MAXPATHL - 1);
|
vim_strncpy(ff_expand_buffer, fname, MAXPATHL - 1);
|
||||||
#ifdef UNIX
|
url = true;
|
||||||
url = TRUE;
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
ff_expand_buffer[0] = NUL;
|
ff_expand_buffer[0] = NUL;
|
||||||
#ifdef UNIX
|
if (!os_get_file_info((char *)fname, &file_info)) {
|
||||||
if (mch_stat((char *)fname, &st) < 0)
|
|
||||||
#else
|
|
||||||
if (vim_FullName(fname, ff_expand_buffer, MAXPATHL, TRUE) == FAIL)
|
|
||||||
#endif
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check against list of already visited files */
|
/* check against list of already visited files */
|
||||||
for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) {
|
for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) {
|
||||||
if (
|
if ((url && fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0)
|
||||||
#ifdef UNIX
|
|| (!url && vp->ffv_dev_valid
|
||||||
!url ? (vp->ffv_dev_valid && vp->ffv_dev == st.st_dev
|
&& vp->ffv_dev == file_info.stat.st_dev
|
||||||
&& vp->ffv_ino == st.st_ino)
|
&& vp->ffv_ino == file_info.stat.st_ino)) {
|
||||||
:
|
|
||||||
#endif
|
|
||||||
fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0
|
|
||||||
) {
|
|
||||||
/* are the wildcard parts equal */
|
/* are the wildcard parts equal */
|
||||||
if (ff_wc_equal(vp->ffv_wc_path, wc_path) == TRUE)
|
if (ff_wc_equal(vp->ffv_wc_path, wc_path) == TRUE)
|
||||||
/* already visited */
|
/* already visited */
|
||||||
@ -1171,19 +1158,15 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
|
|||||||
vp = (ff_visited_T *)alloc((unsigned)(sizeof(ff_visited_T)
|
vp = (ff_visited_T *)alloc((unsigned)(sizeof(ff_visited_T)
|
||||||
+ STRLEN(ff_expand_buffer)));
|
+ STRLEN(ff_expand_buffer)));
|
||||||
|
|
||||||
#ifdef UNIX
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
vp->ffv_dev_valid = TRUE;
|
vp->ffv_dev_valid = TRUE;
|
||||||
vp->ffv_ino = st.st_ino;
|
vp->ffv_ino = file_info.stat.st_ino;
|
||||||
vp->ffv_dev = st.st_dev;
|
vp->ffv_dev = file_info.stat.st_dev;
|
||||||
vp->ffv_fname[0] = NUL;
|
vp->ffv_fname[0] = NUL;
|
||||||
} else {
|
} else {
|
||||||
vp->ffv_dev_valid = FALSE;
|
vp->ffv_dev_valid = FALSE;
|
||||||
STRCPY(vp->ffv_fname, ff_expand_buffer);
|
STRCPY(vp->ffv_fname, ff_expand_buffer);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
STRCPY(vp->ffv_fname, ff_expand_buffer);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (wc_path != NULL)
|
if (wc_path != NULL)
|
||||||
vp->ffv_wc_path = vim_strsave(wc_path);
|
vp->ffv_wc_path = vim_strsave(wc_path);
|
||||||
|
34
src/fileio.c
34
src/fileio.c
@ -4813,12 +4813,11 @@ int vim_rename(char_u *from, char_u *to)
|
|||||||
int n;
|
int n;
|
||||||
char *errmsg = NULL;
|
char *errmsg = NULL;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
struct stat st;
|
|
||||||
long perm;
|
long perm;
|
||||||
#ifdef HAVE_ACL
|
#ifdef HAVE_ACL
|
||||||
vim_acl_T acl; /* ACL from original file */
|
vim_acl_T acl; /* ACL from original file */
|
||||||
#endif
|
#endif
|
||||||
int use_tmp_file = FALSE;
|
bool use_tmp_file = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When the names are identical, there is nothing to do. When they refer
|
* When the names are identical, there is nothing to do. When they refer
|
||||||
@ -4827,30 +4826,25 @@ int vim_rename(char_u *from, char_u *to)
|
|||||||
*/
|
*/
|
||||||
if (fnamecmp(from, to) == 0) {
|
if (fnamecmp(from, to) == 0) {
|
||||||
if (p_fic && STRCMP(path_tail(from), path_tail(to)) != 0)
|
if (p_fic && STRCMP(path_tail(from), path_tail(to)) != 0)
|
||||||
use_tmp_file = TRUE;
|
use_tmp_file = true;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Fail if the "from" file doesn't exist. Avoids that "to" is deleted.
|
||||||
* Fail if the "from" file doesn't exist. Avoids that "to" is deleted.
|
FileInfo from_info;
|
||||||
*/
|
if (!os_get_file_info((char *)from, &from_info)) {
|
||||||
if (mch_stat((char *)from, &st) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#ifdef UNIX
|
|
||||||
{
|
|
||||||
struct stat st_to;
|
|
||||||
|
|
||||||
/* It's possible for the source and destination to be the same file.
|
|
||||||
* This happens when "from" and "to" differ in case and are on a FAT32
|
|
||||||
* filesystem. In that case go through a temp file name. */
|
|
||||||
if (mch_stat((char *)to, &st_to) >= 0
|
|
||||||
&& st.st_dev == st_to.st_dev
|
|
||||||
&& st.st_ino == st_to.st_ino)
|
|
||||||
use_tmp_file = TRUE;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
// It's possible for the source and destination to be the same file.
|
||||||
|
// This happens when "from" and "to" differ in case and are on a FAT32
|
||||||
|
// filesystem. In that case go through a temp file name.
|
||||||
|
FileInfo to_info;
|
||||||
|
if (os_get_file_info((char *)to, &to_info)
|
||||||
|
&& os_file_info_id_equal(&from_info, &to_info)) {
|
||||||
|
use_tmp_file = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (use_tmp_file) {
|
if (use_tmp_file) {
|
||||||
char_u tempname[MAXPATHL + 1];
|
char_u tempname[MAXPATHL + 1];
|
||||||
|
@ -52,8 +52,7 @@ static int cs_find_common(char *opt, char *pat, int, int, int,
|
|||||||
char_u *cmdline);
|
char_u *cmdline);
|
||||||
static int cs_help(exarg_T *eap);
|
static int cs_help(exarg_T *eap);
|
||||||
static void clear_csinfo(int i);
|
static void clear_csinfo(int i);
|
||||||
static int cs_insert_filelist(char *, char *, char *,
|
static int cs_insert_filelist(char *, char *, char *, FileInfo *file_info);
|
||||||
struct stat *);
|
|
||||||
static int cs_kill(exarg_T *eap);
|
static int cs_kill(exarg_T *eap);
|
||||||
static void cs_kill_execute(int, char *);
|
static void cs_kill_execute(int, char *);
|
||||||
static cscmd_T * cs_lookup_cmd(exarg_T *eap);
|
static cscmd_T * cs_lookup_cmd(exarg_T *eap);
|
||||||
@ -481,8 +480,6 @@ cs_add_common (
|
|||||||
char *flags
|
char *flags
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
struct stat statbuf;
|
|
||||||
int ret;
|
|
||||||
char *fname = NULL;
|
char *fname = NULL;
|
||||||
char *fname2 = NULL;
|
char *fname2 = NULL;
|
||||||
char *ppath = NULL;
|
char *ppath = NULL;
|
||||||
@ -503,28 +500,25 @@ cs_add_common (
|
|||||||
goto add_err;
|
goto add_err;
|
||||||
fname = (char *)vim_strnsave((char_u *)fname, len);
|
fname = (char *)vim_strnsave((char_u *)fname, len);
|
||||||
free(fbuf);
|
free(fbuf);
|
||||||
ret = stat(fname, &statbuf);
|
FileInfo file_info;
|
||||||
if (ret < 0) {
|
bool file_info_ok = os_get_file_info(fname, &file_info);
|
||||||
|
if (!file_info_ok) {
|
||||||
staterr:
|
staterr:
|
||||||
if (p_csverbose)
|
if (p_csverbose)
|
||||||
cs_stat_emsg(fname);
|
cs_stat_emsg(fname);
|
||||||
goto add_err;
|
goto add_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the prepend path (arg2), expand it, and try to stat it */
|
// get the prepend path (arg2), expand it, and see if it exists
|
||||||
if (arg2 != NULL) {
|
if (arg2 != NULL) {
|
||||||
struct stat statbuf2;
|
|
||||||
|
|
||||||
ppath = (char *)alloc(MAXPATHL + 1);
|
ppath = (char *)alloc(MAXPATHL + 1);
|
||||||
|
|
||||||
expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL);
|
expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL);
|
||||||
ret = stat(ppath, &statbuf2);
|
if (!os_file_exists((char_u *)ppath))
|
||||||
if (ret < 0)
|
|
||||||
goto staterr;
|
goto staterr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if filename is a directory, append the cscope database name to it */
|
/* if filename is a directory, append the cscope database name to it */
|
||||||
if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
|
if ((file_info.stat.st_mode & S_IFMT) == S_IFDIR) {
|
||||||
fname2 = (char *)alloc((unsigned)(strlen(CSCOPE_DBFILE) + strlen(fname) + 2));
|
fname2 = (char *)alloc((unsigned)(strlen(CSCOPE_DBFILE) + strlen(fname) + 2));
|
||||||
|
|
||||||
while (fname[strlen(fname)-1] == '/'
|
while (fname[strlen(fname)-1] == '/'
|
||||||
@ -538,23 +532,18 @@ staterr:
|
|||||||
else
|
else
|
||||||
(void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE);
|
(void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE);
|
||||||
|
|
||||||
ret = stat(fname2, &statbuf);
|
file_info_ok = os_get_file_info(fname2, &file_info);
|
||||||
if (ret < 0) {
|
if (!file_info_ok) {
|
||||||
if (p_csverbose)
|
if (p_csverbose)
|
||||||
cs_stat_emsg(fname2);
|
cs_stat_emsg(fname2);
|
||||||
goto add_err;
|
goto add_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = cs_insert_filelist(fname2, ppath, flags, &statbuf);
|
i = cs_insert_filelist(fname2, ppath, flags, &file_info);
|
||||||
}
|
}
|
||||||
#if defined(UNIX)
|
else if (S_ISREG(file_info.stat.st_mode) || S_ISLNK(file_info.stat.st_mode))
|
||||||
else if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode))
|
|
||||||
#else
|
|
||||||
/* WIN32 - substitute define S_ISREG from os_unix_defs.h */
|
|
||||||
else if (((statbuf.st_mode) & S_IFMT) == S_IFREG)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
i = cs_insert_filelist(fname, ppath, flags, &statbuf);
|
i = cs_insert_filelist(fname, ppath, flags, &file_info);
|
||||||
} else {
|
} else {
|
||||||
if (p_csverbose)
|
if (p_csverbose)
|
||||||
(void)EMSG2(
|
(void)EMSG2(
|
||||||
@ -1223,53 +1212,16 @@ static char *GetWin32Error(void)
|
|||||||
*
|
*
|
||||||
* insert a new cscope database filename into the filelist
|
* insert a new cscope database filename into the filelist
|
||||||
*/
|
*/
|
||||||
static int cs_insert_filelist(char *fname, char *ppath, char *flags, struct stat *sb)
|
static int cs_insert_filelist(char *fname, char *ppath, char *flags,
|
||||||
|
FileInfo *file_info)
|
||||||
{
|
{
|
||||||
short i, j;
|
short i, j;
|
||||||
#ifndef UNIX
|
|
||||||
BY_HANDLE_FILE_INFORMATION bhfi;
|
|
||||||
|
|
||||||
/* On windows 9x GetFileInformationByHandle doesn't work, so skip it */
|
|
||||||
if (!mch_windows95()) {
|
|
||||||
switch (win32_fileinfo(fname, &bhfi)) {
|
|
||||||
case FILEINFO_ENC_FAIL: /* enc_to_utf16() failed */
|
|
||||||
case FILEINFO_READ_FAIL: /* CreateFile() failed */
|
|
||||||
if (p_csverbose) {
|
|
||||||
char *cant_msg = _("E625: cannot open cscope database: %s");
|
|
||||||
char *winmsg = GetWin32Error();
|
|
||||||
|
|
||||||
if (winmsg != NULL) {
|
|
||||||
(void)EMSG2(cant_msg, winmsg);
|
|
||||||
LocalFree(winmsg);
|
|
||||||
} else
|
|
||||||
/* subst filename if can't get error text */
|
|
||||||
(void)EMSG2(cant_msg, fname);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
case FILEINFO_INFO_FAIL: /* GetFileInformationByHandle() failed */
|
|
||||||
if (p_csverbose)
|
|
||||||
(void)EMSG(_("E626: cannot get cscope database information"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
i = -1; /* can be set to the index of an empty item in csinfo */
|
i = -1; /* can be set to the index of an empty item in csinfo */
|
||||||
for (j = 0; j < csinfo_size; j++) {
|
for (j = 0; j < csinfo_size; j++) {
|
||||||
if (csinfo[j].fname != NULL
|
if (csinfo[j].fname != NULL
|
||||||
#if defined(UNIX)
|
&& csinfo[j].st_dev == file_info->stat.st_dev
|
||||||
&& csinfo[j].st_dev == sb->st_dev && csinfo[j].st_ino == sb->st_ino
|
&& csinfo[j].st_ino == file_info->stat.st_ino) {
|
||||||
#else
|
|
||||||
/* compare pathnames first */
|
|
||||||
&& ((path_full_compare(csinfo[j].fname, fname, FALSE) & kEqualFiles)
|
|
||||||
/* if not Windows 9x, test index file attributes too */
|
|
||||||
|| (!mch_windows95()
|
|
||||||
&& csinfo[j].nVolume == bhfi.dwVolumeSerialNumber
|
|
||||||
&& csinfo[j].nIndexHigh == bhfi.nFileIndexHigh
|
|
||||||
&& csinfo[j].nIndexLow == bhfi.nFileIndexLow))
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
if (p_csverbose)
|
if (p_csverbose)
|
||||||
(void)EMSG(_("E568: duplicate cscope database not added"));
|
(void)EMSG(_("E568: duplicate cscope database not added"));
|
||||||
return -1;
|
return -1;
|
||||||
@ -1312,15 +1264,8 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags, struct stat
|
|||||||
} else
|
} else
|
||||||
csinfo[i].flags = NULL;
|
csinfo[i].flags = NULL;
|
||||||
|
|
||||||
#if defined(UNIX)
|
csinfo[i].st_dev = file_info->stat.st_dev;
|
||||||
csinfo[i].st_dev = sb->st_dev;
|
csinfo[i].st_ino = file_info->stat.st_ino;
|
||||||
csinfo[i].st_ino = sb->st_ino;
|
|
||||||
|
|
||||||
#else
|
|
||||||
csinfo[i].nVolume = bhfi.dwVolumeSerialNumber;
|
|
||||||
csinfo[i].nIndexLow = bhfi.nFileIndexLow;
|
|
||||||
csinfo[i].nIndexHigh = bhfi.nFileIndexHigh;
|
|
||||||
#endif
|
|
||||||
return i;
|
return i;
|
||||||
} /* cs_insert_filelist */
|
} /* cs_insert_filelist */
|
||||||
|
|
||||||
|
@ -51,10 +51,9 @@ typedef struct csi {
|
|||||||
char * flags; /* additional cscope flags/options (e.g, -p2) */
|
char * flags; /* additional cscope flags/options (e.g, -p2) */
|
||||||
#if defined(UNIX)
|
#if defined(UNIX)
|
||||||
pid_t pid; /* PID of the connected cscope process. */
|
pid_t pid; /* PID of the connected cscope process. */
|
||||||
dev_t st_dev; /* ID of dev containing cscope db */
|
|
||||||
ino_t st_ino; /* inode number of cscope db */
|
|
||||||
#else
|
|
||||||
#endif
|
#endif
|
||||||
|
uint64_t st_dev; /* ID of dev containing cscope db */
|
||||||
|
uint64_t st_ino; /* inode number of cscope db */
|
||||||
|
|
||||||
FILE * fr_fp; /* from cscope: FILE. */
|
FILE * fr_fp; /* from cscope: FILE. */
|
||||||
FILE * to_fp; /* to cscope: FILE. */
|
FILE * to_fp; /* to cscope: FILE. */
|
||||||
|
13
src/main.c
13
src/main.c
@ -2130,14 +2130,13 @@ process_env (
|
|||||||
*/
|
*/
|
||||||
static int file_owned(char *fname)
|
static int file_owned(char *fname)
|
||||||
{
|
{
|
||||||
struct stat s;
|
|
||||||
uid_t uid = getuid();
|
uid_t uid = getuid();
|
||||||
|
FileInfo file_info;
|
||||||
return !(mch_stat(fname, &s) != 0 || s.st_uid != uid
|
bool file_owned = os_get_file_info(fname, &file_info)
|
||||||
# ifdef HAVE_LSTAT
|
&& file_info.stat.st_uid == uid;
|
||||||
|| mch_lstat(fname, &s) != 0 || s.st_uid != uid
|
bool link_owned = os_get_file_info_link(fname, &file_info)
|
||||||
# endif
|
&& file_info.stat.st_uid == uid;
|
||||||
);
|
return file_owned && link_owned;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
31
src/undo.c
31
src/undo.c
@ -1106,10 +1106,6 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
int perm;
|
int perm;
|
||||||
int write_ok = FALSE;
|
int write_ok = FALSE;
|
||||||
#ifdef UNIX
|
|
||||||
struct stat st_old;
|
|
||||||
struct stat st_new;
|
|
||||||
#endif
|
|
||||||
int do_crypt = FALSE;
|
int do_crypt = FALSE;
|
||||||
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
@ -1215,14 +1211,17 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
* this fails, set the protection bits for the group same as the
|
* this fails, set the protection bits for the group same as the
|
||||||
* protection bits for others.
|
* protection bits for others.
|
||||||
*/
|
*/
|
||||||
if (mch_stat((char *)buf->b_ffname, &st_old) >= 0
|
FileInfo file_info_old;
|
||||||
&& mch_stat((char *)file_name, &st_new) >= 0
|
FileInfo file_info_new;
|
||||||
&& st_new.st_gid != st_old.st_gid
|
if (os_get_file_info((char *)buf->b_ffname, &file_info_old)
|
||||||
|
&& os_get_file_info((char *)file_name, &file_info_new)
|
||||||
|
&& file_info_old.stat.st_gid != file_info_new.stat.st_gid
|
||||||
# ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */
|
# ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */
|
||||||
&& fchown(fd, (uid_t)-1, st_old.st_gid) != 0
|
&& fchown(fd, (uid_t)-1, file_info_old.stat.st_gid) != 0
|
||||||
# endif
|
# endif
|
||||||
)
|
) {
|
||||||
os_setperm(file_name, (perm & 0707) | ((perm & 07) << 3));
|
os_setperm(file_name, (perm & 0707) | ((perm & 07) << 3));
|
||||||
|
}
|
||||||
# ifdef HAVE_SELINUX
|
# ifdef HAVE_SELINUX
|
||||||
if (buf->b_ffname != NULL)
|
if (buf->b_ffname != NULL)
|
||||||
mch_copy_sec(buf->b_ffname, file_name);
|
mch_copy_sec(buf->b_ffname, file_name);
|
||||||
@ -1342,10 +1341,6 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
|
|||||||
char_u magic_buf[UF_START_MAGIC_LEN];
|
char_u magic_buf[UF_START_MAGIC_LEN];
|
||||||
#ifdef U_DEBUG
|
#ifdef U_DEBUG
|
||||||
int *uhp_table_used;
|
int *uhp_table_used;
|
||||||
#endif
|
|
||||||
#ifdef UNIX
|
|
||||||
struct stat st_orig;
|
|
||||||
struct stat st_undo;
|
|
||||||
#endif
|
#endif
|
||||||
int do_decrypt = FALSE;
|
int do_decrypt = FALSE;
|
||||||
|
|
||||||
@ -1357,10 +1352,12 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
|
|||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
/* For safety we only read an undo file if the owner is equal to the
|
/* For safety we only read an undo file if the owner is equal to the
|
||||||
* owner of the text file or equal to the current user. */
|
* owner of the text file or equal to the current user. */
|
||||||
if (mch_stat((char *)orig_name, &st_orig) >= 0
|
FileInfo file_info_orig;
|
||||||
&& mch_stat((char *)file_name, &st_undo) >= 0
|
FileInfo file_info_undo;
|
||||||
&& st_orig.st_uid != st_undo.st_uid
|
if (os_get_file_info((char *)orig_name, &file_info_orig)
|
||||||
&& st_undo.st_uid != getuid()) {
|
&& os_get_file_info((char *)file_name, &file_info_undo)
|
||||||
|
&& file_info_orig.stat.st_uid != file_info_undo.stat.st_uid
|
||||||
|
&& file_info_undo.stat.st_uid != getuid()) {
|
||||||
if (p_verbose > 0) {
|
if (p_verbose > 0) {
|
||||||
verbose_enter();
|
verbose_enter();
|
||||||
smsg((char_u *)_("Not reading undo file, owner differs: %s"),
|
smsg((char_u *)_("Not reading undo file, owner differs: %s"),
|
||||||
|
Loading…
Reference in New Issue
Block a user