fileinfo: rename os_get_file_info{,_link,_fd}

This commit is contained in:
Stefan Hoffmann
2014-08-27 19:14:44 +02:00
parent 9ee1c3604c
commit 5d074a0aa6
14 changed files with 74 additions and 75 deletions

View File

@@ -948,7 +948,7 @@ void ex_diffpatch(exarg_T *eap)
// Only continue if the output file was created. // Only continue if the output file was created.
FileInfo file_info; FileInfo file_info;
bool info_ok = os_get_file_info((char *)tmp_new, &file_info); bool info_ok = os_fileinfo((char *)tmp_new, &file_info);
off_t filesize = os_fileinfo_size(&file_info); off_t filesize = os_fileinfo_size(&file_info);
if (!info_ok || filesize == 0) { if (!info_ok || filesize == 0) {
EMSG(_("E816: Cannot read patch output")); EMSG(_("E816: Cannot read patch output"));

View File

@@ -9166,7 +9166,7 @@ static void f_getfsize(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_NUMBER; rettv->v_type = VAR_NUMBER;
FileInfo file_info; FileInfo file_info;
if (os_get_file_info(fname, &file_info)) { if (os_fileinfo(fname, &file_info)) {
off_t filesize = os_fileinfo_size(&file_info); off_t filesize = os_fileinfo_size(&file_info);
if (os_isdir((char_u *)fname)) if (os_isdir((char_u *)fname))
rettv->vval.v_number = 0; rettv->vval.v_number = 0;
@@ -9191,7 +9191,7 @@ static void f_getftime(typval_T *argvars, typval_T *rettv)
char *fname = (char *)get_tv_string(&argvars[0]); char *fname = (char *)get_tv_string(&argvars[0]);
FileInfo file_info; FileInfo file_info;
if (os_get_file_info(fname, &file_info)) { if (os_fileinfo(fname, &file_info)) {
rettv->vval.v_number = (varnumber_T)file_info.stat.st_mtim.tv_sec; rettv->vval.v_number = (varnumber_T)file_info.stat.st_mtim.tv_sec;
} else { } else {
rettv->vval.v_number = -1; rettv->vval.v_number = -1;
@@ -9211,7 +9211,7 @@ static void f_getftype(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
FileInfo file_info; FileInfo file_info;
if (os_get_file_info_link((char *)fname, &file_info)) { if (os_fileinfo_link((char *)fname, &file_info)) {
uint64_t mode = file_info.stat.st_mode; uint64_t mode = file_info.stat.st_mode;
#ifdef S_ISREG #ifdef S_ISREG
if (S_ISREG(mode)) if (S_ISREG(mode))

View File

@@ -1533,7 +1533,7 @@ void write_viminfo(char_u *file, int forceit)
*/ */
FileInfo old_info; // FileInfo of existing viminfo file FileInfo old_info; // FileInfo of existing viminfo file
if (os_get_file_info((char *)fname, &old_info) if (os_fileinfo((char *)fname, &old_info)
&& getuid() != ROOT_UID && getuid() != ROOT_UID
&& !(old_info.stat.st_uid == getuid() && !(old_info.stat.st_uid == getuid()
? (old_info.stat.st_mode & 0200) ? (old_info.stat.st_mode & 0200)

View File

@@ -472,7 +472,7 @@ readfile (
if (newfile && !read_stdin && !read_buffer) { if (newfile && !read_stdin && !read_buffer) {
/* Remember time of file. */ /* Remember time of file. */
FileInfo file_info; FileInfo file_info;
if (os_get_file_info((char *)fname, &file_info)) { if (os_fileinfo((char *)fname, &file_info)) {
buf_store_file_info(curbuf, &file_info); buf_store_file_info(curbuf, &file_info);
curbuf->b_mtime_read = curbuf->b_mtime; curbuf->b_mtime_read = curbuf->b_mtime;
#ifdef UNIX #ifdef UNIX
@@ -2583,7 +2583,7 @@ buf_write (
#if defined(UNIX) #if defined(UNIX)
perm = -1; perm = -1;
FileInfo file_info_old; FileInfo file_info_old;
if (!os_get_file_info((char *)fname, &file_info_old)) { if (!os_fileinfo((char *)fname, &file_info_old)) {
newfile = TRUE; newfile = TRUE;
} else { } else {
perm = file_info_old.stat.st_mode; perm = file_info_old.stat.st_mode;
@@ -2629,7 +2629,7 @@ buf_write (
goto fail; goto fail;
} }
if (overwriting) { if (overwriting) {
os_get_file_info((char *)fname, &file_info_old); os_fileinfo((char *)fname, &file_info_old);
} }
} }
@@ -2713,7 +2713,7 @@ buf_write (
* - we don't have write permission in the directory * - we don't have write permission in the directory
*/ */
if (os_fileinfo_hardlinks(&file_info_old) > 1 if (os_fileinfo_hardlinks(&file_info_old) > 1
|| !os_get_file_info_link((char *)fname, &file_info) || !os_fileinfo_link((char *)fname, &file_info)
|| !os_file_info_id_equal(&file_info, &file_info_old)) { || !os_file_info_id_equal(&file_info, &file_info_old)) {
backup_copy = TRUE; backup_copy = TRUE;
} else } else
@@ -2728,7 +2728,7 @@ buf_write (
STRCPY(IObuff, fname); STRCPY(IObuff, fname);
for (i = 4913;; i += 123) { for (i = 4913;; i += 123) {
sprintf((char *)path_tail(IObuff), "%d", i); sprintf((char *)path_tail(IObuff), "%d", i);
if (!os_get_file_info_link((char *)IObuff, &file_info)) { if (!os_fileinfo_link((char *)IObuff, &file_info)) {
break; break;
} }
} }
@@ -2739,7 +2739,7 @@ buf_write (
else { else {
# ifdef UNIX # ifdef UNIX
os_fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid); os_fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid);
if (!os_get_file_info((char *)IObuff, &file_info) if (!os_fileinfo((char *)IObuff, &file_info)
|| file_info.stat.st_uid != file_info_old.stat.st_uid || file_info.stat.st_uid != file_info_old.stat.st_uid
|| file_info.stat.st_gid != file_info_old.stat.st_gid || file_info.stat.st_gid != file_info_old.stat.st_gid
|| (long)file_info.stat.st_mode != perm) { || (long)file_info.stat.st_mode != perm) {
@@ -2759,7 +2759,7 @@ buf_write (
*/ */
if ((bkc_flags & BKC_BREAKSYMLINK) || (bkc_flags & BKC_BREAKHARDLINK)) { if ((bkc_flags & BKC_BREAKSYMLINK) || (bkc_flags & BKC_BREAKHARDLINK)) {
# ifdef UNIX # ifdef UNIX
bool file_info_link_ok = os_get_file_info_link((char *)fname, &file_info); bool file_info_link_ok = os_fileinfo_link((char *)fname, &file_info);
/* Symlinks. */ /* Symlinks. */
if ((bkc_flags & BKC_BREAKSYMLINK) if ((bkc_flags & BKC_BREAKSYMLINK)
@@ -2837,7 +2837,7 @@ buf_write (
/* /*
* Check if backup file already exists. * Check if backup file already exists.
*/ */
if (os_get_file_info((char *)backup, &file_info_new)) { if (os_fileinfo((char *)backup, &file_info_new)) {
/* /*
* Check if backup file is same as original file. * Check if backup file is same as original file.
* May happen when modname() gave the same file back (e.g. silly * May happen when modname() gave the same file back (e.g. silly
@@ -2861,7 +2861,7 @@ buf_write (
wp = backup; wp = backup;
*wp = 'z'; *wp = 'z';
while (*wp > 'a' while (*wp > 'a'
&& os_get_file_info((char *)backup, &file_info_new)) { && os_fileinfo((char *)backup, &file_info_new)) {
--*wp; --*wp;
} }
/* They all exist??? Must be something wrong. */ /* They all exist??? Must be something wrong. */
@@ -3202,7 +3202,7 @@ nobackup:
/* Don't delete the file when it's a hard or symbolic link. */ /* Don't delete the file when it's a hard or symbolic link. */
if ((!newfile && os_fileinfo_hardlinks(&file_info) > 1) if ((!newfile && os_fileinfo_hardlinks(&file_info) > 1)
|| (os_get_file_info_link((char *)fname, &file_info) || (os_fileinfo_link((char *)fname, &file_info)
&& !os_file_info_id_equal(&file_info, &file_info_old))) { && !os_file_info_id_equal(&file_info, &file_info_old))) {
errmsg = (char_u *)_("E166: Can't open linked file for writing"); errmsg = (char_u *)_("E166: Can't open linked file for writing");
} else } else
@@ -3416,7 +3416,7 @@ restore_backup:
/* don't change the owner when it's already OK, some systems remove /* don't change the owner when it's already OK, some systems remove
* permission or ACL stuff */ * permission or ACL stuff */
FileInfo file_info; FileInfo file_info;
if (!os_get_file_info((char *)wfname, &file_info) if (!os_fileinfo((char *)wfname, &file_info)
|| file_info.stat.st_uid != file_info_old.stat.st_uid || file_info.stat.st_uid != file_info_old.stat.st_uid
|| file_info.stat.st_gid != file_info_old.stat.st_gid) { || file_info.stat.st_gid != file_info_old.stat.st_gid) {
os_fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid); os_fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid);
@@ -3713,7 +3713,7 @@ nofail:
/* Update the timestamp to avoid an "overwrite changed file" /* Update the timestamp to avoid an "overwrite changed file"
* prompt when writing again. */ * prompt when writing again. */
if (os_get_file_info((char *)fname, &file_info_old)) { if (os_fileinfo((char *)fname, &file_info_old)) {
buf_store_file_info(buf, &file_info_old); buf_store_file_info(buf, &file_info_old);
buf->b_mtime_read = buf->b_mtime; buf->b_mtime_read = buf->b_mtime;
} }
@@ -4536,7 +4536,7 @@ int vim_rename(char_u *from, char_u *to)
// 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; FileInfo from_info;
if (!os_get_file_info((char *)from, &from_info)) { if (!os_fileinfo((char *)from, &from_info)) {
return -1; return -1;
} }
@@ -4544,7 +4544,7 @@ int vim_rename(char_u *from, char_u *to)
// This happens when "from" and "to" differ in case and are on a FAT32 // This happens when "from" and "to" differ in case and are on a FAT32
// filesystem. In that case go through a temp file name. // filesystem. In that case go through a temp file name.
FileInfo to_info; FileInfo to_info;
if (os_get_file_info((char *)to, &to_info) if (os_fileinfo((char *)to, &to_info)
&& os_file_info_id_equal(&from_info, &to_info)) { && os_file_info_id_equal(&from_info, &to_info)) {
use_tmp_file = true; use_tmp_file = true;
} }
@@ -4812,7 +4812,7 @@ buf_check_timestamp (
bool file_info_ok; bool file_info_ok;
if (!(buf->b_flags & BF_NOTEDITED) if (!(buf->b_flags & BF_NOTEDITED)
&& buf->b_mtime != 0 && buf->b_mtime != 0
&& (!(file_info_ok = os_get_file_info((char *)buf->b_ffname, &file_info)) && (!(file_info_ok = os_fileinfo((char *)buf->b_ffname, &file_info))
|| time_differs((long)file_info.stat.st_mtim.tv_sec, buf->b_mtime) || time_differs((long)file_info.stat.st_mtim.tv_sec, buf->b_mtime)
|| (int)file_info.stat.st_mode != buf->b_orig_mode || (int)file_info.stat.st_mode != buf->b_orig_mode
)) { )) {

View File

@@ -473,7 +473,7 @@ cs_add_common (
fname = (char *)vim_strnsave((char_u *)fname, len); fname = (char *)vim_strnsave((char_u *)fname, len);
free(fbuf); free(fbuf);
FileInfo file_info; FileInfo file_info;
bool file_info_ok = os_get_file_info(fname, &file_info); bool file_info_ok = os_fileinfo(fname, &file_info);
if (!file_info_ok) { if (!file_info_ok) {
staterr: staterr:
if (p_csverbose) if (p_csverbose)
@@ -504,7 +504,7 @@ staterr:
else else
(void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE); (void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE);
file_info_ok = os_get_file_info(fname2, &file_info); file_info_ok = os_fileinfo(fname2, &file_info);
if (!file_info_ok) { if (!file_info_ok) {
if (p_csverbose) if (p_csverbose)
cs_stat_emsg(fname2); cs_stat_emsg(fname2);

View File

@@ -2094,9 +2094,9 @@ static int file_owned(char *fname)
{ {
uid_t uid = getuid(); uid_t uid = getuid();
FileInfo file_info; FileInfo file_info;
bool file_owned = os_get_file_info(fname, &file_info) bool file_owned = os_fileinfo(fname, &file_info)
&& file_info.stat.st_uid == uid; && file_info.stat.st_uid == uid;
bool link_owned = os_get_file_info_link(fname, &file_info) bool link_owned = os_fileinfo_link(fname, &file_info)
&& file_info.stat.st_uid == uid; && file_info.stat.st_uid == uid;
return file_owned && link_owned; return file_owned && link_owned;
} }

View File

@@ -122,8 +122,7 @@ memfile_T *mf_open(char_u *fname, int flags)
* mf_blocknr_max must be rounded up. * mf_blocknr_max must be rounded up.
*/ */
FileInfo file_info; FileInfo file_info;
if (mfp->mf_fd >= 0 if (mfp->mf_fd >= 0 && os_fileinfo_fd(mfp->mf_fd, &file_info)) {
&& os_get_file_info_fd(mfp->mf_fd, &file_info)) {
uint64_t blocksize = os_fileinfo_blocksize(&file_info); uint64_t blocksize = os_fileinfo_blocksize(&file_info);
if (blocksize >= MIN_SWAP_PAGE_SIZE && blocksize <= MAX_SWAP_PAGE_SIZE) { if (blocksize >= MIN_SWAP_PAGE_SIZE && blocksize <= MAX_SWAP_PAGE_SIZE) {
mfp->mf_page_size = blocksize; mfp->mf_page_size = blocksize;
@@ -1018,7 +1017,7 @@ mf_do_open (
*/ */
FileInfo file_info; FileInfo file_info;
if ((flags & O_CREAT) if ((flags & O_CREAT)
&& os_get_file_info_link((char *)mfp->mf_fname, &file_info)) { && os_fileinfo_link((char *)mfp->mf_fname, &file_info)) {
mfp->mf_fd = -1; mfp->mf_fd = -1;
EMSG(_("E300: Swap file already exists (symlink attack?)")); EMSG(_("E300: Swap file already exists (symlink attack?)"));
} else { } else {

View File

@@ -686,7 +686,7 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf)
} }
} }
FileInfo file_info; FileInfo file_info;
if (os_get_file_info((char *)buf->b_ffname, &file_info)) { if (os_fileinfo((char *)buf->b_ffname, &file_info)) {
long_to_char((long)file_info.stat.st_mtim.tv_sec, b0p->b0_mtime); long_to_char((long)file_info.stat.st_mtim.tv_sec, b0p->b0_mtime);
long_to_char((long)os_file_info_get_inode(&file_info), b0p->b0_ino); long_to_char((long)os_file_info_get_inode(&file_info), b0p->b0_ino);
buf_store_file_info(buf, &file_info); buf_store_file_info(buf, &file_info);
@@ -961,8 +961,8 @@ void ml_recover(void)
FileInfo swp_file_info; FileInfo swp_file_info;
mtime = char_to_long(b0p->b0_mtime); mtime = char_to_long(b0p->b0_mtime);
if (curbuf->b_ffname != NULL if (curbuf->b_ffname != NULL
&& os_get_file_info((char *)curbuf->b_ffname, &org_file_info) && os_fileinfo((char *)curbuf->b_ffname, &org_file_info)
&& ((os_get_file_info((char *)mfp->mf_fname, &swp_file_info) && ((os_fileinfo((char *)mfp->mf_fname, &swp_file_info)
&& org_file_info.stat.st_mtim.tv_sec && org_file_info.stat.st_mtim.tv_sec
> swp_file_info.stat.st_mtim.tv_sec) > swp_file_info.stat.st_mtim.tv_sec)
|| org_file_info.stat.st_mtim.tv_sec != mtime)) { || org_file_info.stat.st_mtim.tv_sec != mtime)) {
@@ -1494,7 +1494,7 @@ static time_t swapfile_info(char_u *fname)
/* print the swap file date */ /* print the swap file date */
FileInfo file_info; FileInfo file_info;
if (os_get_file_info((char *)fname, &file_info)) { if (os_fileinfo((char *)fname, &file_info)) {
#ifdef UNIX #ifdef UNIX
/* print name of owner of the file */ /* print name of owner of the file */
if (os_get_uname(file_info.stat.st_uid, uname, B0_UNAME_SIZE) == OK) { if (os_get_uname(file_info.stat.st_uid, uname, B0_UNAME_SIZE) == OK) {
@@ -1630,7 +1630,7 @@ void ml_sync_all(int check_file, int check_char)
* call ml_preserve() to get rid of all negative numbered blocks. * call ml_preserve() to get rid of all negative numbered blocks.
*/ */
FileInfo file_info; FileInfo file_info;
if (!os_get_file_info((char *)buf->b_ffname, &file_info) if (!os_fileinfo((char *)buf->b_ffname, &file_info)
|| file_info.stat.st_mtim.tv_sec != buf->b_mtime_read || file_info.stat.st_mtim.tv_sec != buf->b_mtime_read
|| os_fileinfo_size(&file_info) != buf->b_orig_size) { || os_fileinfo_size(&file_info) != buf->b_orig_size) {
ml_preserve(buf, FALSE); ml_preserve(buf, FALSE);
@@ -3180,7 +3180,7 @@ attention_message (
msg_outtrans(buf->b_fname); msg_outtrans(buf->b_fname);
MSG_PUTS("\"\n"); MSG_PUTS("\"\n");
FileInfo file_info; FileInfo file_info;
if (os_get_file_info((char *)buf->b_fname, &file_info)) { if (os_fileinfo((char *)buf->b_fname, &file_info)) {
MSG_PUTS(_(" dated: ")); MSG_PUTS(_(" dated: "));
x = file_info.stat.st_mtim.tv_sec; x = file_info.stat.st_mtim.tv_sec;
p = ctime(&x); // includes '\n' p = ctime(&x); // includes '\n'
@@ -3294,7 +3294,7 @@ findswapname (
// Extra security check: When a swap file is a symbolic link, this // Extra security check: When a swap file is a symbolic link, this
// is most likely a symlink attack. // is most likely a symlink attack.
FileInfo file_info; FileInfo file_info;
bool file_or_link_found = os_get_file_info_link((char *)fname, &file_info); bool file_or_link_found = os_fileinfo_link((char *)fname, &file_info);
if (!file_or_link_found) { if (!file_or_link_found) {
break; break;
} }
@@ -3558,7 +3558,7 @@ fnamecmp_ino (
int retval_s; /* flag: buf_s valid */ int retval_s; /* flag: buf_s valid */
FileInfo file_info; FileInfo file_info;
if (os_get_file_info((char *)fname_c, &file_info)) { if (os_fileinfo((char *)fname_c, &file_info)) {
ino_c = os_file_info_get_inode(&file_info); ino_c = os_file_info_get_inode(&file_info);
} }
@@ -3567,7 +3567,7 @@ fnamecmp_ino (
* the swap file may be outdated. If that fails (e.g. this path is not * the swap file may be outdated. If that fails (e.g. this path is not
* valid on this machine), use the inode from block 0. * valid on this machine), use the inode from block 0.
*/ */
if (os_get_file_info((char *)fname_s, &file_info)) { if (os_fileinfo((char *)fname_s, &file_info)) {
ino_s = os_file_info_get_inode(&file_info); ino_s = os_file_info_get_inode(&file_info);
} else { } else {
ino_s = (uint64_t)ino_block0; ino_s = (uint64_t)ino_block0;

View File

@@ -331,7 +331,7 @@ int os_remove(const char *path)
/// @param path Path to the file. /// @param path Path to the file.
/// @param[out] file_info Pointer to a FileInfo to put the information in. /// @param[out] file_info Pointer to a FileInfo to put the information in.
/// @return `true` on success, `false` for failure. /// @return `true` on success, `false` for failure.
bool os_get_file_info(const char *path, FileInfo *file_info) bool os_fileinfo(const char *path, FileInfo *file_info)
{ {
return os_stat(path, &(file_info->stat)); return os_stat(path, &(file_info->stat));
} }
@@ -341,7 +341,7 @@ bool os_get_file_info(const char *path, FileInfo *file_info)
/// @param path Path to the file. /// @param path Path to the file.
/// @param[out] file_info Pointer to a FileInfo to put the information in. /// @param[out] file_info Pointer to a FileInfo to put the information in.
/// @return `true` on success, `false` for failure. /// @return `true` on success, `false` for failure.
bool os_get_file_info_link(const char *path, FileInfo *file_info) bool os_fileinfo_link(const char *path, FileInfo *file_info)
{ {
uv_fs_t request; uv_fs_t request;
int result = uv_fs_lstat(uv_default_loop(), &request, path, NULL); int result = uv_fs_lstat(uv_default_loop(), &request, path, NULL);
@@ -355,7 +355,7 @@ bool os_get_file_info_link(const char *path, FileInfo *file_info)
/// @param file_descriptor File descriptor of the file. /// @param file_descriptor File descriptor of the file.
/// @param[out] file_info Pointer to a FileInfo to put the information in. /// @param[out] file_info Pointer to a FileInfo to put the information in.
/// @return `true` on success, `false` for failure. /// @return `true` on success, `false` for failure.
bool os_get_file_info_fd(int file_descriptor, FileInfo *file_info) bool os_fileinfo_fd(int file_descriptor, FileInfo *file_info)
{ {
uv_fs_t request; uv_fs_t request;
int result = uv_fs_fstat(uv_default_loop(), &request, file_descriptor, NULL); int result = uv_fs_fstat(uv_default_loop(), &request, file_descriptor, NULL);

View File

@@ -328,7 +328,7 @@ int len /* buffer size, only used when name gets longer */
struct dirent *dp; struct dirent *dp;
FileInfo file_info; FileInfo file_info;
if (os_get_file_info_link((char *)name, &file_info)) { if (os_fileinfo_link((char *)name, &file_info)) {
/* Open the directory where the file is located. */ /* Open the directory where the file is located. */
slash = vim_strrchr(name, '/'); slash = vim_strrchr(name, '/');
if (slash == NULL) { if (slash == NULL) {
@@ -354,7 +354,7 @@ int len /* buffer size, only used when name gets longer */
STRLCPY(newname + (tail - name), dp->d_name, STRLCPY(newname + (tail - name), dp->d_name,
MAXPATHL - (tail - name) + 1); MAXPATHL - (tail - name) + 1);
FileInfo file_info_new; FileInfo file_info_new;
if (os_get_file_info_link((char *)newname, &file_info_new) if (os_fileinfo_link((char *)newname, &file_info_new)
&& os_file_info_id_equal(&file_info, &file_info_new)) { && os_file_info_id_equal(&file_info, &file_info_new)) {
STRCPY(tail, dp->d_name); STRCPY(tail, dp->d_name);
break; break;

View File

@@ -1304,7 +1304,7 @@ void simplify_filename(char_u *filename)
saved_char = p[-1]; saved_char = p[-1];
p[-1] = NUL; p[-1] = NUL;
FileInfo file_info; FileInfo file_info;
if (!os_get_file_info_link((char *)filename, &file_info)) { if (!os_fileinfo_link((char *)filename, &file_info)) {
do_strip = TRUE; do_strip = TRUE;
} }
p[-1] = saved_char; p[-1] = saved_char;
@@ -1327,7 +1327,7 @@ void simplify_filename(char_u *filename)
* components. */ * components. */
saved_char = *tail; saved_char = *tail;
*tail = NUL; *tail = NUL;
if (os_get_file_info((char *)filename, &file_info)) { if (os_fileinfo((char *)filename, &file_info)) {
do_strip = TRUE; do_strip = TRUE;
} }
else else
@@ -1343,11 +1343,11 @@ void simplify_filename(char_u *filename)
* component's parent directory.) */ * component's parent directory.) */
FileInfo new_file_info; FileInfo new_file_info;
if (p == start && relative) { if (p == start && relative) {
os_get_file_info(".", &new_file_info); os_fileinfo(".", &new_file_info);
} else { } else {
saved_char = *p; saved_char = *p;
*p = NUL; *p = NUL;
os_get_file_info((char *)filename, &new_file_info); os_fileinfo((char *)filename, &new_file_info);
*p = saved_char; *p = saved_char;
} }

View File

@@ -2564,7 +2564,7 @@ static char_u *get_mef_name(void)
STRCAT(name, p + 2); STRCAT(name, p + 2);
// Don't accept a symbolic link, its a security risk. // Don't accept a symbolic link, its a security risk.
FileInfo file_info; FileInfo file_info;
bool file_or_link_found = os_get_file_info_link((char *)name, &file_info); bool file_or_link_found = os_fileinfo_link((char *)name, &file_info);
if (!file_or_link_found) { if (!file_or_link_found) {
break; break;
} }

View File

@@ -1116,8 +1116,8 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
*/ */
FileInfo file_info_old; FileInfo file_info_old;
FileInfo file_info_new; FileInfo file_info_new;
if (os_get_file_info((char *)buf->b_ffname, &file_info_old) if (os_fileinfo((char *)buf->b_ffname, &file_info_old)
&& os_get_file_info((char *)file_name, &file_info_new) && os_fileinfo((char *)file_name, &file_info_new)
&& file_info_old.stat.st_gid != file_info_new.stat.st_gid && file_info_old.stat.st_gid != file_info_new.stat.st_gid
&& os_fchown(fd, -1, file_info_old.stat.st_gid) != 0) { && os_fchown(fd, -1, file_info_old.stat.st_gid) != 0) {
os_setperm(file_name, (perm & 0707) | ((perm & 07) << 3)); os_setperm(file_name, (perm & 0707) | ((perm & 07) << 3));
@@ -1249,8 +1249,8 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
* owner of the text file or equal to the current user. */ * owner of the text file or equal to the current user. */
FileInfo file_info_orig; FileInfo file_info_orig;
FileInfo file_info_undo; FileInfo file_info_undo;
if (os_get_file_info((char *)orig_name, &file_info_orig) if (os_fileinfo((char *)orig_name, &file_info_orig)
&& os_get_file_info((char *)file_name, &file_info_undo) && os_fileinfo((char *)file_name, &file_info_undo)
&& file_info_orig.stat.st_uid != file_info_undo.stat.st_uid && file_info_orig.stat.st_uid != file_info_undo.stat.st_uid
&& file_info_undo.stat.st_uid != getuid()) { && file_info_undo.stat.st_uid != getuid()) {
if (p_verbose > 0) { if (p_verbose > 0) {

View File

@@ -483,63 +483,63 @@ describe('fs function', function()
return file_info return file_info
end end
describe('os_get_file_info', function() describe('os_fileinfo', function()
it('returns false if given a non-existing file', function() it('returns false if given a non-existing file', function()
local file_info = file_info_new() local file_info = file_info_new()
assert.is_false((fs.os_get_file_info('/non-existent', file_info))) assert.is_false((fs.os_fileinfo('/non-existent', file_info)))
end) end)
it('returns true if given an existing file and fills file_info', function() it('returns true if given an existing file and fills file_info', function()
local file_info = file_info_new() local file_info = file_info_new()
local path = 'unit-test-directory/test.file' local path = 'unit-test-directory/test.file'
assert.is_true((fs.os_get_file_info(path, file_info))) assert.is_true((fs.os_fileinfo(path, file_info)))
assert.is_true((is_file_info_filled(file_info))) assert.is_true((is_file_info_filled(file_info)))
end) end)
it('returns the file info of the linked file, not the link', function() it('returns the file info of the linked file, not the link', function()
local file_info = file_info_new() local file_info = file_info_new()
local path = 'unit-test-directory/test_link.file' local path = 'unit-test-directory/test_link.file'
assert.is_true((fs.os_get_file_info(path, file_info))) assert.is_true((fs.os_fileinfo(path, file_info)))
assert.is_true((is_file_info_filled(file_info))) assert.is_true((is_file_info_filled(file_info)))
local mode = tonumber(file_info[0].stat.st_mode) local mode = tonumber(file_info[0].stat.st_mode)
return eq(ffi.C.kS_IFREG, (bit.band(mode, ffi.C.kS_IFMT))) return eq(ffi.C.kS_IFREG, (bit.band(mode, ffi.C.kS_IFMT)))
end) end)
end) end)
describe('os_get_file_info_link', function() describe('os_fileinfo_link', function()
it('returns false if given a non-existing file', function() it('returns false if given a non-existing file', function()
local file_info = file_info_new() local file_info = file_info_new()
assert.is_false((fs.os_get_file_info_link('/non-existent', file_info))) assert.is_false((fs.os_fileinfo_link('/non-existent', file_info)))
end) end)
it('returns true if given an existing file and fills file_info', function() it('returns true if given an existing file and fills file_info', function()
local file_info = file_info_new() local file_info = file_info_new()
local path = 'unit-test-directory/test.file' local path = 'unit-test-directory/test.file'
assert.is_true((fs.os_get_file_info_link(path, file_info))) assert.is_true((fs.os_fileinfo_link(path, file_info)))
assert.is_true((is_file_info_filled(file_info))) assert.is_true((is_file_info_filled(file_info)))
end) end)
it('returns the file info of the link, not the linked file', function() it('returns the file info of the link, not the linked file', function()
local file_info = file_info_new() local file_info = file_info_new()
local path = 'unit-test-directory/test_link.file' local path = 'unit-test-directory/test_link.file'
assert.is_true((fs.os_get_file_info_link(path, file_info))) assert.is_true((fs.os_fileinfo_link(path, file_info)))
assert.is_true((is_file_info_filled(file_info))) assert.is_true((is_file_info_filled(file_info)))
local mode = tonumber(file_info[0].stat.st_mode) local mode = tonumber(file_info[0].stat.st_mode)
eq(ffi.C.kS_IFLNK, (bit.band(mode, ffi.C.kS_IFMT))) eq(ffi.C.kS_IFLNK, (bit.band(mode, ffi.C.kS_IFMT)))
end) end)
end) end)
describe('os_get_file_info_fd', function() describe('os_fileinfo_fd', function()
it('returns false if given an invalid file descriptor', function() it('returns false if given an invalid file descriptor', function()
local file_info = file_info_new() local file_info = file_info_new()
assert.is_false((fs.os_get_file_info_fd(-1, file_info))) assert.is_false((fs.os_fileinfo_fd(-1, file_info)))
end) end)
it('returns true if given a file descriptor and fills file_info', function() it('returns true if given a file descriptor and fills file_info', function()
local file_info = file_info_new() local file_info = file_info_new()
local path = 'unit-test-directory/test.file' local path = 'unit-test-directory/test.file'
local fd = ffi.C.open(path, 0) local fd = ffi.C.open(path, 0)
assert.is_true((fs.os_get_file_info_fd(fd, file_info))) assert.is_true((fs.os_fileinfo_fd(fd, file_info)))
assert.is_true((is_file_info_filled(file_info))) assert.is_true((is_file_info_filled(file_info)))
ffi.C.close(fd) ffi.C.close(fd)
end) end)
@@ -551,8 +551,8 @@ describe('fs function', function()
local file_info_2 = file_info_new() local file_info_2 = file_info_new()
local path_1 = 'unit-test-directory/test.file' local path_1 = 'unit-test-directory/test.file'
local path_2 = 'unit-test-directory/test_2.file' local path_2 = 'unit-test-directory/test_2.file'
assert.is_true((fs.os_get_file_info(path_1, file_info_1))) assert.is_true((fs.os_fileinfo(path_1, file_info_1)))
assert.is_true((fs.os_get_file_info(path_2, file_info_2))) assert.is_true((fs.os_fileinfo(path_2, file_info_2)))
assert.is_false((fs.os_file_info_id_equal(file_info_1, file_info_2))) assert.is_false((fs.os_file_info_id_equal(file_info_1, file_info_2)))
end) end)
@@ -560,8 +560,8 @@ describe('fs function', function()
local file_info_1 = file_info_new() local file_info_1 = file_info_new()
local file_info_2 = file_info_new() local file_info_2 = file_info_new()
local path = 'unit-test-directory/test.file' local path = 'unit-test-directory/test.file'
assert.is_true((fs.os_get_file_info(path, file_info_1))) assert.is_true((fs.os_fileinfo(path, file_info_1)))
assert.is_true((fs.os_get_file_info(path, file_info_2))) assert.is_true((fs.os_fileinfo(path, file_info_2)))
assert.is_true((fs.os_file_info_id_equal(file_info_1, file_info_2))) assert.is_true((fs.os_file_info_id_equal(file_info_1, file_info_2)))
end) end)
@@ -570,8 +570,8 @@ describe('fs function', function()
local file_info_2 = file_info_new() local file_info_2 = file_info_new()
local path_1 = 'unit-test-directory/test.file' local path_1 = 'unit-test-directory/test.file'
local path_2 = 'unit-test-directory/test_link.file' local path_2 = 'unit-test-directory/test_link.file'
assert.is_true((fs.os_get_file_info(path_1, file_info_1))) assert.is_true((fs.os_fileinfo(path_1, file_info_1)))
assert.is_true((fs.os_get_file_info(path_2, file_info_2))) assert.is_true((fs.os_fileinfo(path_2, file_info_2)))
assert.is_true((fs.os_file_info_id_equal(file_info_1, file_info_2))) assert.is_true((fs.os_file_info_id_equal(file_info_1, file_info_2)))
end) end)
end) end)
@@ -581,7 +581,7 @@ describe('fs function', function()
local file_info = file_info_new() local file_info = file_info_new()
local file_id = file_id_new() local file_id = file_id_new()
local path = 'unit-test-directory/test.file' local path = 'unit-test-directory/test.file'
assert.is_true((fs.os_get_file_info(path, file_info))) assert.is_true((fs.os_fileinfo(path, file_info)))
fs.os_file_info_get_id(file_info, file_id) fs.os_file_info_get_id(file_info, file_id)
eq(file_info[0].stat.st_ino, file_id[0].inode) eq(file_info[0].stat.st_ino, file_id[0].inode)
eq(file_info[0].stat.st_dev, file_id[0].device_id) eq(file_info[0].stat.st_dev, file_id[0].device_id)
@@ -592,7 +592,7 @@ describe('fs function', function()
it('returns the inode from file_info', function() it('returns the inode from file_info', function()
local file_info = file_info_new() local file_info = file_info_new()
local path = 'unit-test-directory/test.file' local path = 'unit-test-directory/test.file'
assert.is_true((fs.os_get_file_info(path, file_info))) assert.is_true((fs.os_fileinfo(path, file_info)))
local inode = fs.os_file_info_get_inode(file_info) local inode = fs.os_file_info_get_inode(file_info)
eq(file_info[0].stat.st_ino, inode) eq(file_info[0].stat.st_ino, inode)
end) end)
@@ -607,7 +607,7 @@ describe('fs function', function()
file:close() file:close()
local size = lfs.attributes(path, 'size') local size = lfs.attributes(path, 'size')
local file_info = file_info_new() local file_info = file_info_new()
assert.is_true(fs.os_get_file_info(path, file_info)) assert.is_true(fs.os_fileinfo(path, file_info))
eq(size, fs.os_fileinfo_size(file_info)) eq(size, fs.os_fileinfo_size(file_info))
end) end)
end) end)
@@ -617,10 +617,10 @@ describe('fs function', function()
local path = 'unit-test-directory/test.file' local path = 'unit-test-directory/test.file'
local path_link = 'unit-test-directory/test_hlink.file' local path_link = 'unit-test-directory/test_hlink.file'
local file_info = file_info_new() local file_info = file_info_new()
assert.is_true(fs.os_get_file_info(path, file_info)) assert.is_true(fs.os_fileinfo(path, file_info))
eq(1, fs.os_fileinfo_hardlinks(file_info)) eq(1, fs.os_fileinfo_hardlinks(file_info))
lfs.link(path, path_link) lfs.link(path, path_link)
assert.is_true(fs.os_get_file_info(path, file_info)) assert.is_true(fs.os_fileinfo(path, file_info))
eq(2, fs.os_fileinfo_hardlinks(file_info)) eq(2, fs.os_fileinfo_hardlinks(file_info))
end) end)
end) end)
@@ -634,7 +634,7 @@ describe('fs function', function()
-- using this workaround for now: -- using this workaround for now:
local blksize = lfs.attributes(path).blksize local blksize = lfs.attributes(path).blksize
local file_info = file_info_new() local file_info = file_info_new()
assert.is_true(fs.os_get_file_info(path, file_info)) assert.is_true(fs.os_fileinfo(path, file_info))
if blksize then if blksize then
eq(blksize, fs.os_fileinfo_blocksize(file_info)) eq(blksize, fs.os_fileinfo_blocksize(file_info))
else else
@@ -686,7 +686,7 @@ describe('fs function', function()
local file_info = file_info_new() local file_info = file_info_new()
local path = 'unit-test-directory/test.file' local path = 'unit-test-directory/test.file'
assert.is_true((fs.os_get_file_id(path, file_id))) assert.is_true((fs.os_get_file_id(path, file_id)))
assert.is_true((fs.os_get_file_info(path, file_info))) assert.is_true((fs.os_fileinfo(path, file_info)))
assert.is_true((fs.os_file_id_equal_file_info(file_id, file_info))) assert.is_true((fs.os_file_id_equal_file_info(file_id, file_info)))
end) end)
@@ -696,7 +696,7 @@ describe('fs function', function()
local path_1 = 'unit-test-directory/test.file' local path_1 = 'unit-test-directory/test.file'
local path_2 = 'unit-test-directory/test_2.file' local path_2 = 'unit-test-directory/test_2.file'
assert.is_true((fs.os_get_file_id(path_1, file_id))) assert.is_true((fs.os_get_file_id(path_1, file_id)))
assert.is_true((fs.os_get_file_info(path_2, file_info))) assert.is_true((fs.os_fileinfo(path_2, file_info)))
assert.is_false((fs.os_file_id_equal_file_info(file_id, file_info))) assert.is_false((fs.os_file_id_equal_file_info(file_id, file_info)))
end) end)
end) end)