mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 07:48:18 +00:00
Merge pull request #1054 from stefan991/fileinfo-getter
FileInfo getters for `filesize`, `hardlinks` and `blocksize`
This commit is contained in:
@@ -1314,7 +1314,7 @@ buflist_new (
|
|||||||
* for hard links. */
|
* for hard links. */
|
||||||
FileID file_id;
|
FileID file_id;
|
||||||
bool file_id_valid = (sfname != NULL &&
|
bool file_id_valid = (sfname != NULL &&
|
||||||
os_get_file_id((char *)sfname, &file_id));
|
os_fileid((char *)sfname, &file_id));
|
||||||
if (ffname != NULL && !(flags & BLN_DUMMY)
|
if (ffname != NULL && !(flags & BLN_DUMMY)
|
||||||
&& (buf = buflist_findname_file_id(ffname, &file_id,
|
&& (buf = buflist_findname_file_id(ffname, &file_id,
|
||||||
file_id_valid)) != NULL) {
|
file_id_valid)) != NULL) {
|
||||||
@@ -1671,7 +1671,7 @@ buf_T *buflist_findname_exp(char_u *fname)
|
|||||||
buf_T *buflist_findname(char_u *ffname)
|
buf_T *buflist_findname(char_u *ffname)
|
||||||
{
|
{
|
||||||
FileID file_id;
|
FileID file_id;
|
||||||
bool file_id_valid = os_get_file_id((char *)ffname, &file_id);
|
bool file_id_valid = os_fileid((char *)ffname, &file_id);
|
||||||
return buflist_findname_file_id(ffname, &file_id, file_id_valid);
|
return buflist_findname_file_id(ffname, &file_id, file_id_valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2221,7 +2221,7 @@ setfname (
|
|||||||
* - if the buffer is loaded, fail
|
* - if the buffer is loaded, fail
|
||||||
* - if the buffer is not loaded, delete it from the list
|
* - if the buffer is not loaded, delete it from the list
|
||||||
*/
|
*/
|
||||||
file_id_valid = os_get_file_id((char *)ffname, &file_id);
|
file_id_valid = os_fileid((char *)ffname, &file_id);
|
||||||
if (!(buf->b_flags & BF_DUMMY)) {
|
if (!(buf->b_flags & BF_DUMMY)) {
|
||||||
obuf = buflist_findname_file_id(ffname, &file_id, file_id_valid);
|
obuf = buflist_findname_file_id(ffname, &file_id, file_id_valid);
|
||||||
}
|
}
|
||||||
@@ -2399,7 +2399,7 @@ static int otherfile_buf(buf_T *buf, char_u *ffname,
|
|||||||
/* If no struct stat given, get it now */
|
/* If no struct stat given, get it now */
|
||||||
if (file_id_p == NULL) {
|
if (file_id_p == NULL) {
|
||||||
file_id_p = &file_id;
|
file_id_p = &file_id;
|
||||||
file_id_valid = os_get_file_id((char *)ffname, file_id_p);
|
file_id_valid = os_fileid((char *)ffname, file_id_p);
|
||||||
}
|
}
|
||||||
if (!file_id_valid) {
|
if (!file_id_valid) {
|
||||||
// file_id not valid, assume files are different.
|
// file_id not valid, assume files are different.
|
||||||
@@ -2429,7 +2429,7 @@ void buf_set_file_id(buf_T *buf)
|
|||||||
{
|
{
|
||||||
FileID file_id;
|
FileID file_id;
|
||||||
if (buf->b_fname != NULL
|
if (buf->b_fname != NULL
|
||||||
&& os_get_file_id((char *)buf->b_fname, &file_id)) {
|
&& os_fileid((char *)buf->b_fname, &file_id)) {
|
||||||
buf->file_id_valid = true;
|
buf->file_id_valid = true;
|
||||||
buf->file_id = file_id;
|
buf->file_id = file_id;
|
||||||
} else {
|
} else {
|
||||||
@@ -2441,7 +2441,7 @@ void buf_set_file_id(buf_T *buf)
|
|||||||
static bool buf_same_file_id(buf_T *buf, FileID *file_id)
|
static bool buf_same_file_id(buf_T *buf, FileID *file_id)
|
||||||
{
|
{
|
||||||
return buf->file_id_valid
|
return buf->file_id_valid
|
||||||
&& os_file_id_equal(&(buf->file_id), file_id);
|
&& os_fileid_equal(&(buf->file_id), file_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -512,7 +512,7 @@ struct file_buffer {
|
|||||||
|
|
||||||
long b_mtime; /* last change time of original file */
|
long b_mtime; /* last change time of original file */
|
||||||
long b_mtime_read; /* last change time when reading */
|
long b_mtime_read; /* last change time when reading */
|
||||||
off_t b_orig_size; /* size of original file in bytes */
|
uint64_t b_orig_size; /* size of original file in bytes */
|
||||||
int b_orig_mode; /* mode of original file */
|
int b_orig_mode; /* mode of original file */
|
||||||
|
|
||||||
pos_T b_namedm[NMARKS]; /* current named marks (mark.c) */
|
pos_T b_namedm[NMARKS]; /* current named marks (mark.c) */
|
||||||
|
@@ -947,9 +947,10 @@ void ex_diffpatch(exarg_T *eap)
|
|||||||
os_remove((char *)buf);
|
os_remove((char *)buf);
|
||||||
|
|
||||||
// Only continue if the output file was created.
|
// Only continue if the output file was created.
|
||||||
off_t file_size;
|
FileInfo file_info;
|
||||||
bool file_size_success = os_get_file_size((char *)tmp_new, &file_size);
|
bool info_ok = os_fileinfo((char *)tmp_new, &file_info);
|
||||||
if (!file_size_success || file_size == 0) {
|
uint64_t filesize = os_fileinfo_size(&file_info);
|
||||||
|
if (!info_ok || filesize == 0) {
|
||||||
EMSG(_("E816: Cannot read patch output"));
|
EMSG(_("E816: Cannot read patch output"));
|
||||||
} else {
|
} else {
|
||||||
if (curbuf->b_fname != NULL) {
|
if (curbuf->b_fname != NULL) {
|
||||||
|
@@ -9165,15 +9165,16 @@ static void f_getfsize(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
rettv->v_type = VAR_NUMBER;
|
rettv->v_type = VAR_NUMBER;
|
||||||
|
|
||||||
off_t file_size;
|
FileInfo file_info;
|
||||||
if (os_get_file_size(fname, &file_size)) {
|
if (os_fileinfo(fname, &file_info)) {
|
||||||
|
uint64_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;
|
||||||
else {
|
else {
|
||||||
rettv->vval.v_number = (varnumber_T)file_size;
|
rettv->vval.v_number = (varnumber_T)filesize;
|
||||||
|
|
||||||
/* non-perfect check for overflow */
|
/* non-perfect check for overflow */
|
||||||
if ((off_t)rettv->vval.v_number != file_size) {
|
if ((uint64_t)rettv->vval.v_number != filesize) {
|
||||||
rettv->vval.v_number = -2;
|
rettv->vval.v_number = -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9190,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;
|
||||||
@@ -9210,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))
|
||||||
|
@@ -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)
|
||||||
|
@@ -2417,13 +2417,13 @@ do_source (
|
|||||||
*/
|
*/
|
||||||
save_current_SID = current_SID;
|
save_current_SID = current_SID;
|
||||||
FileID file_id;
|
FileID file_id;
|
||||||
bool file_id_ok = os_get_file_id((char *)fname_exp, &file_id);
|
bool file_id_ok = os_fileid((char *)fname_exp, &file_id);
|
||||||
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.
|
// Compare dev/ino when possible, it catches symbolic links.
|
||||||
// Also compare file names, the inode may change when the file was edited.
|
// Also compare file names, the inode may change when the file was edited.
|
||||||
bool file_id_equal = file_id_ok && si->file_id_valid
|
bool file_id_equal = file_id_ok && si->file_id_valid
|
||||||
&& os_file_id_equal(&(si->file_id), &file_id);
|
&& os_fileid_equal(&(si->file_id), &file_id);
|
||||||
if (si->sn_name != NULL
|
if (si->sn_name != NULL
|
||||||
&& (file_id_equal || fnamecmp(si->sn_name, fname_exp) == 0)) {
|
&& (file_id_equal || fnamecmp(si->sn_name, fname_exp) == 0)) {
|
||||||
break;
|
break;
|
||||||
|
@@ -1097,7 +1097,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
|
|||||||
url = true;
|
url = true;
|
||||||
} else {
|
} else {
|
||||||
ff_expand_buffer[0] = NUL;
|
ff_expand_buffer[0] = NUL;
|
||||||
if (!os_get_file_id((char *)fname, &file_id)) {
|
if (!os_fileid((char *)fname, &file_id)) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1106,7 +1106,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
|
|||||||
for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) {
|
for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) {
|
||||||
if ((url && fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0)
|
if ((url && fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0)
|
||||||
|| (!url && vp->file_id_valid
|
|| (!url && vp->file_id_valid
|
||||||
&& os_file_id_equal(&(vp->file_id), &file_id))) {
|
&& os_fileid_equal(&(vp->file_id), &file_id))) {
|
||||||
/* 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 */
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2712,9 +2712,9 @@ buf_write (
|
|||||||
* - it's a symbolic link
|
* - it's a symbolic link
|
||||||
* - we don't have write permission in the directory
|
* - we don't have write permission in the directory
|
||||||
*/
|
*/
|
||||||
if (file_info_old.stat.st_nlink > 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_fileinfo_id_equal(&file_info, &file_info_old)) {
|
||||||
backup_copy = TRUE;
|
backup_copy = TRUE;
|
||||||
} else
|
} else
|
||||||
# endif
|
# endif
|
||||||
@@ -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,20 +2759,20 @@ 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)
|
||||||
&& file_info_link_ok
|
&& file_info_link_ok
|
||||||
&& !os_file_info_id_equal(&file_info, &file_info_old)) {
|
&& !os_fileinfo_id_equal(&file_info, &file_info_old)) {
|
||||||
backup_copy = FALSE;
|
backup_copy = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hardlinks. */
|
/* Hardlinks. */
|
||||||
if ((bkc_flags & BKC_BREAKHARDLINK)
|
if ((bkc_flags & BKC_BREAKHARDLINK)
|
||||||
&& file_info_old.stat.st_nlink > 1
|
&& os_fileinfo_hardlinks(&file_info_old) > 1
|
||||||
&& (!file_info_link_ok
|
&& (!file_info_link_ok
|
||||||
|| os_file_info_id_equal(&file_info, &file_info_old))) {
|
|| os_fileinfo_id_equal(&file_info, &file_info_old))) {
|
||||||
backup_copy = FALSE;
|
backup_copy = FALSE;
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
@@ -2837,14 +2837,14 @@ 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
|
||||||
* link). If we don't check here, we either ruin the file when
|
* link). If we don't check here, we either ruin the file when
|
||||||
* copying or erase it after writing.
|
* copying or erase it after writing.
|
||||||
*/
|
*/
|
||||||
if (os_file_info_id_equal(&file_info_new, &file_info_old)) {
|
if (os_fileinfo_id_equal(&file_info_new, &file_info_old)) {
|
||||||
free(backup);
|
free(backup);
|
||||||
backup = NULL; /* no backup file to delete */
|
backup = NULL; /* no backup file to delete */
|
||||||
}
|
}
|
||||||
@@ -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. */
|
||||||
@@ -3201,9 +3201,9 @@ nobackup:
|
|||||||
FileInfo file_info;
|
FileInfo file_info;
|
||||||
|
|
||||||
/* 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 && file_info_old.stat.st_nlink > 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_fileinfo_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
|
||||||
#endif
|
#endif
|
||||||
@@ -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,8 +4544,8 @@ 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_fileinfo_id_equal(&from_info, &to_info)) {
|
||||||
use_tmp_file = true;
|
use_tmp_file = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4790,7 +4790,7 @@ buf_check_timestamp (
|
|||||||
int helpmesg = FALSE;
|
int helpmesg = FALSE;
|
||||||
int reload = FALSE;
|
int reload = FALSE;
|
||||||
int can_reload = FALSE;
|
int can_reload = FALSE;
|
||||||
off_t orig_size = buf->b_orig_size;
|
uint64_t orig_size = buf->b_orig_size;
|
||||||
int orig_mode = buf->b_orig_mode;
|
int orig_mode = buf->b_orig_mode;
|
||||||
static int busy = FALSE;
|
static int busy = FALSE;
|
||||||
int n;
|
int n;
|
||||||
@@ -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
|
||||||
)) {
|
)) {
|
||||||
@@ -5127,9 +5127,10 @@ void buf_reload(buf_T *buf, int orig_mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void buf_store_file_info(buf_T *buf, FileInfo *file_info)
|
void buf_store_file_info(buf_T *buf, FileInfo *file_info)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
buf->b_mtime = (long)file_info->stat.st_mtim.tv_sec;
|
buf->b_mtime = (long)file_info->stat.st_mtim.tv_sec;
|
||||||
buf->b_orig_size = file_info->stat.st_size;
|
buf->b_orig_size = os_fileinfo_size(file_info);
|
||||||
buf->b_orig_mode = (int)file_info->stat.st_mode;
|
buf->b_orig_mode = (int)file_info->stat.st_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
@@ -1181,7 +1181,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
|
|||||||
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
|
||||||
&& os_file_id_equal_file_info(&(csinfo[j].file_id), file_info)) {
|
&& os_fileid_equal_fileinfo(&(csinfo[j].file_id), file_info)) {
|
||||||
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;
|
||||||
@@ -1224,7 +1224,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
|
|||||||
} else
|
} else
|
||||||
csinfo[i].flags = NULL;
|
csinfo[i].flags = NULL;
|
||||||
|
|
||||||
os_file_info_get_id(file_info, &(csinfo[i].file_id));
|
os_fileinfo_id(file_info, &(csinfo[i].file_id));
|
||||||
return i;
|
return i;
|
||||||
} /* cs_insert_filelist */
|
} /* cs_insert_filelist */
|
||||||
|
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
@@ -122,11 +122,11 @@ 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);
|
||||||
&& file_info.stat.st_blksize >= MIN_SWAP_PAGE_SIZE
|
if (blocksize >= MIN_SWAP_PAGE_SIZE && blocksize <= MAX_SWAP_PAGE_SIZE) {
|
||||||
&& file_info.stat.st_blksize <= MAX_SWAP_PAGE_SIZE) {
|
mfp->mf_page_size = blocksize;
|
||||||
mfp->mf_page_size = file_info.stat.st_blksize;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mfp->mf_fd < 0 || (flags & (O_TRUNC|O_EXCL))
|
if (mfp->mf_fd < 0 || (flags & (O_TRUNC|O_EXCL))
|
||||||
@@ -1017,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 {
|
||||||
|
@@ -686,9 +686,9 @@ 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_fileinfo_inode(&file_info), b0p->b0_ino);
|
||||||
buf_store_file_info(buf, &file_info);
|
buf_store_file_info(buf, &file_info);
|
||||||
buf->b_mtime_read = buf->b_mtime;
|
buf->b_mtime_read = buf->b_mtime;
|
||||||
} else {
|
} else {
|
||||||
@@ -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,9 +1630,9 @@ 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
|
||||||
|| (off_t)file_info.stat.st_size != buf->b_orig_size) {
|
|| os_fileinfo_size(&file_info) != buf->b_orig_size) {
|
||||||
ml_preserve(buf, FALSE);
|
ml_preserve(buf, FALSE);
|
||||||
did_check_timestamps = FALSE;
|
did_check_timestamps = FALSE;
|
||||||
need_check_timestamps = TRUE; /* give message later */
|
need_check_timestamps = TRUE; /* give message later */
|
||||||
@@ -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,8 +3558,8 @@ 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_fileinfo_inode(&file_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -3567,8 +3567,8 @@ 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_fileinfo_inode(&file_info);
|
||||||
} else {
|
} else {
|
||||||
ino_s = (uint64_t)ino_block0;
|
ino_s = (uint64_t)ino_block0;
|
||||||
}
|
}
|
||||||
|
@@ -258,20 +258,6 @@ int os_file_is_writable(const char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the size of a file in bytes.
|
|
||||||
///
|
|
||||||
/// @param[out] size pointer to an off_t to put the size into.
|
|
||||||
/// @return `true` for success, `false` for failure.
|
|
||||||
bool os_get_file_size(const char *name, off_t *size)
|
|
||||||
{
|
|
||||||
uv_stat_t statbuf;
|
|
||||||
if (os_stat(name, &statbuf)) {
|
|
||||||
*size = statbuf.st_size;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Rename a file or directory.
|
/// Rename a file or directory.
|
||||||
///
|
///
|
||||||
/// @return `OK` for success, `FAIL` for failure.
|
/// @return `OK` for success, `FAIL` for failure.
|
||||||
@@ -345,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));
|
||||||
}
|
}
|
||||||
@@ -355,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);
|
||||||
@@ -369,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);
|
||||||
@@ -381,7 +367,7 @@ bool os_get_file_info_fd(int file_descriptor, FileInfo *file_info)
|
|||||||
/// Compare the inodes of two FileInfos
|
/// Compare the inodes of two FileInfos
|
||||||
///
|
///
|
||||||
/// @return `true` if the two FileInfos represent the same file.
|
/// @return `true` if the two FileInfos represent the same file.
|
||||||
bool os_file_info_id_equal(const FileInfo *file_info_1,
|
bool os_fileinfo_id_equal(const FileInfo *file_info_1,
|
||||||
const FileInfo *file_info_2)
|
const FileInfo *file_info_2)
|
||||||
{
|
{
|
||||||
return file_info_1->stat.st_ino == file_info_2->stat.st_ino
|
return file_info_1->stat.st_ino == file_info_2->stat.st_ino
|
||||||
@@ -392,7 +378,7 @@ bool os_file_info_id_equal(const FileInfo *file_info_1,
|
|||||||
///
|
///
|
||||||
/// @param file_info Pointer to the `FileInfo`
|
/// @param file_info Pointer to the `FileInfo`
|
||||||
/// @param[out] file_id Pointer to a `FileID`
|
/// @param[out] file_id Pointer to a `FileID`
|
||||||
void os_file_info_get_id(const FileInfo *file_info, FileID *file_id)
|
void os_fileinfo_id(const FileInfo *file_info, FileID *file_id)
|
||||||
{
|
{
|
||||||
file_id->inode = file_info->stat.st_ino;
|
file_id->inode = file_info->stat.st_ino;
|
||||||
file_id->device_id = file_info->stat.st_dev;
|
file_id->device_id = file_info->stat.st_dev;
|
||||||
@@ -403,17 +389,44 @@ void os_file_info_get_id(const FileInfo *file_info, FileID *file_id)
|
|||||||
/// @deprecated Use `FileID` instead, this function is only needed in memline.c
|
/// @deprecated Use `FileID` instead, this function is only needed in memline.c
|
||||||
/// @param file_info Pointer to the `FileInfo`
|
/// @param file_info Pointer to the `FileInfo`
|
||||||
/// @return the inode number
|
/// @return the inode number
|
||||||
uint64_t os_file_info_get_inode(const FileInfo *file_info)
|
uint64_t os_fileinfo_inode(const FileInfo *file_info)
|
||||||
{
|
{
|
||||||
return file_info->stat.st_ino;
|
return file_info->stat.st_ino;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the size of a file from a `FileInfo`.
|
||||||
|
///
|
||||||
|
/// @return filesize in bytes.
|
||||||
|
uint64_t os_fileinfo_size(const FileInfo *file_info)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
return file_info->stat.st_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the number of hardlinks from a `FileInfo`.
|
||||||
|
///
|
||||||
|
/// @return number of hardlinks.
|
||||||
|
uint64_t os_fileinfo_hardlinks(const FileInfo *file_info)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
return file_info->stat.st_nlink;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the blocksize from a `FileInfo`.
|
||||||
|
///
|
||||||
|
/// @return blocksize in bytes.
|
||||||
|
uint64_t os_fileinfo_blocksize(const FileInfo *file_info)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
return file_info->stat.st_blksize;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the `FileID` for a given path
|
/// Get the `FileID` for a given path
|
||||||
///
|
///
|
||||||
/// @param path Path to the file.
|
/// @param path Path to the file.
|
||||||
/// @param[out] file_info Pointer to a `FileID` to fill in.
|
/// @param[out] file_info Pointer to a `FileID` to fill in.
|
||||||
/// @return `true` on sucess, `false` for failure.
|
/// @return `true` on sucess, `false` for failure.
|
||||||
bool os_get_file_id(const char *path, FileID *file_id)
|
bool os_fileid(const char *path, FileID *file_id)
|
||||||
{
|
{
|
||||||
uv_stat_t statbuf;
|
uv_stat_t statbuf;
|
||||||
if (os_stat(path, &statbuf)) {
|
if (os_stat(path, &statbuf)) {
|
||||||
@@ -429,7 +442,7 @@ bool os_get_file_id(const char *path, FileID *file_id)
|
|||||||
/// @param file_id_1 Pointer to first `FileID`
|
/// @param file_id_1 Pointer to first `FileID`
|
||||||
/// @param file_id_2 Pointer to second `FileID`
|
/// @param file_id_2 Pointer to second `FileID`
|
||||||
/// @return `true` if the two `FileID`s represent te same file.
|
/// @return `true` if the two `FileID`s represent te same file.
|
||||||
bool os_file_id_equal(const FileID *file_id_1, const FileID *file_id_2)
|
bool os_fileid_equal(const FileID *file_id_1, const FileID *file_id_2)
|
||||||
{
|
{
|
||||||
return file_id_1->inode == file_id_2->inode
|
return file_id_1->inode == file_id_2->inode
|
||||||
&& file_id_1->device_id == file_id_2->device_id;
|
&& file_id_1->device_id == file_id_2->device_id;
|
||||||
@@ -440,7 +453,7 @@ bool os_file_id_equal(const FileID *file_id_1, const FileID *file_id_2)
|
|||||||
/// @param file_id Pointer to a `FileID`
|
/// @param file_id Pointer to a `FileID`
|
||||||
/// @param file_info Pointer to a `FileInfo`
|
/// @param file_info Pointer to a `FileInfo`
|
||||||
/// @return `true` if the `FileID` and the `FileInfo` represent te same file.
|
/// @return `true` if the `FileID` and the `FileInfo` represent te same file.
|
||||||
bool os_file_id_equal_file_info(const FileID *file_id,
|
bool os_fileid_equal_fileinfo(const FileID *file_id,
|
||||||
const FileInfo *file_info)
|
const FileInfo *file_info)
|
||||||
{
|
{
|
||||||
return file_id->inode == file_info->stat.st_ino
|
return file_id->inode == file_info->stat.st_ino
|
||||||
|
@@ -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,8 +354,8 @@ 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_fileinfo_id_equal(&file_info, &file_info_new)) {
|
||||||
STRCPY(tail, dp->d_name);
|
STRCPY(tail, dp->d_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -61,10 +61,10 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname)
|
|||||||
FileID file_id_1, file_id_2;
|
FileID file_id_1, file_id_2;
|
||||||
|
|
||||||
expand_env(s1, exp1, MAXPATHL);
|
expand_env(s1, exp1, MAXPATHL);
|
||||||
bool id_ok_1 = os_get_file_id((char *)exp1, &file_id_1);
|
bool id_ok_1 = os_fileid((char *)exp1, &file_id_1);
|
||||||
bool id_ok_2 = os_get_file_id((char *)s2, &file_id_2);
|
bool id_ok_2 = os_fileid((char *)s2, &file_id_2);
|
||||||
if (!id_ok_1 && !id_ok_2) {
|
if (!id_ok_1 && !id_ok_2) {
|
||||||
// If os_get_file_id() doesn't work, may compare the names.
|
// If os_fileid() doesn't work, may compare the names.
|
||||||
if (checkname) {
|
if (checkname) {
|
||||||
vim_FullName(exp1, full1, MAXPATHL, FALSE);
|
vim_FullName(exp1, full1, MAXPATHL, FALSE);
|
||||||
vim_FullName(s2, full2, MAXPATHL, FALSE);
|
vim_FullName(s2, full2, MAXPATHL, FALSE);
|
||||||
@@ -77,7 +77,7 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname)
|
|||||||
if (!id_ok_1 || !id_ok_2) {
|
if (!id_ok_1 || !id_ok_2) {
|
||||||
return kOneFileMissing;
|
return kOneFileMissing;
|
||||||
}
|
}
|
||||||
if (os_file_id_equal(&file_id_1, &file_id_2)) {
|
if (os_fileid_equal(&file_id_1, &file_id_2)) {
|
||||||
return kEqualFiles;
|
return kEqualFiles;
|
||||||
}
|
}
|
||||||
return kDifferentFiles;
|
return kDifferentFiles;
|
||||||
@@ -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,15 +1343,15 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!os_file_info_id_equal(&file_info, &new_file_info)) {
|
if (!os_fileinfo_id_equal(&file_info, &new_file_info)) {
|
||||||
do_strip = FALSE;
|
do_strip = FALSE;
|
||||||
/* We don't disable stripping of later
|
/* We don't disable stripping of later
|
||||||
* components since the unstripped path name is
|
* components since the unstripped path name is
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
@@ -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) {
|
||||||
|
@@ -47,6 +47,7 @@ describe('fs function', function()
|
|||||||
os.remove('unit-test-directory/test.file')
|
os.remove('unit-test-directory/test.file')
|
||||||
os.remove('unit-test-directory/test_2.file')
|
os.remove('unit-test-directory/test_2.file')
|
||||||
os.remove('unit-test-directory/test_link.file')
|
os.remove('unit-test-directory/test_link.file')
|
||||||
|
os.remove('unit-test-directory/test_hlink.file')
|
||||||
lfs.rmdir('unit-test-directory')
|
lfs.rmdir('unit-test-directory')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -482,86 +483,86 @@ 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)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('os_file_info_id_equal', function()
|
describe('os_fileinfo_id_equal', function()
|
||||||
it('returns false if file infos represent different files', function()
|
it('returns false if file infos represent different files', 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_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_fileinfo_id_equal(file_info_1, file_info_2)))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('returns true if file infos represent the same file', function()
|
it('returns true if file infos represent the same file', 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_fileinfo_id_equal(file_info_1, file_info_2)))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('returns true if file infos represent the same file (symlink)', function()
|
it('returns true if file infos represent the same file (symlink)', function()
|
||||||
@@ -569,55 +570,103 @@ 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_fileinfo_id_equal(file_info_1, file_info_2)))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('os_file_info_get_id', function()
|
describe('os_fileinfo_id', function()
|
||||||
it('extracts ino/dev from file_info into file_id', function()
|
it('extracts ino/dev from file_info into file_id', 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_fileinfo_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)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('os_file_info_get_inode', function()
|
describe('os_fileinfo_inode', 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_fileinfo_inode(file_info)
|
||||||
eq(file_info[0].stat.st_ino, inode)
|
eq(file_info[0].stat.st_ino, inode)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('os_get_file_id', function()
|
describe('os_fileinfo_size', function()
|
||||||
|
it('returns the correct size of a file', function()
|
||||||
|
local path = 'unit-test-directory/test.file'
|
||||||
|
local file = io.open(path, 'w')
|
||||||
|
file:write('some bytes to get filesize != 0')
|
||||||
|
file:flush()
|
||||||
|
file:close()
|
||||||
|
local size = lfs.attributes(path, 'size')
|
||||||
|
local file_info = file_info_new()
|
||||||
|
assert.is_true(fs.os_fileinfo(path, file_info))
|
||||||
|
eq(size, fs.os_fileinfo_size(file_info))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe('os_fileinfo_hardlinks', function()
|
||||||
|
it('returns the correct number of hardlinks', function()
|
||||||
|
local path = 'unit-test-directory/test.file'
|
||||||
|
local path_link = 'unit-test-directory/test_hlink.file'
|
||||||
|
local file_info = file_info_new()
|
||||||
|
assert.is_true(fs.os_fileinfo(path, file_info))
|
||||||
|
eq(1, fs.os_fileinfo_hardlinks(file_info))
|
||||||
|
lfs.link(path, path_link)
|
||||||
|
assert.is_true(fs.os_fileinfo(path, file_info))
|
||||||
|
eq(2, fs.os_fileinfo_hardlinks(file_info))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe('os_fileinfo_blocksize', function()
|
||||||
|
it('returns the correct blocksize of a file', function()
|
||||||
|
local path = 'unit-test-directory/test.file'
|
||||||
|
-- there is a bug in luafilesystem where
|
||||||
|
-- `lfs.attributes path, 'blksize'` returns the worng value:
|
||||||
|
-- https://github.com/keplerproject/luafilesystem/pull/44
|
||||||
|
-- using this workaround for now:
|
||||||
|
local blksize = lfs.attributes(path).blksize
|
||||||
|
local file_info = file_info_new()
|
||||||
|
assert.is_true(fs.os_fileinfo(path, file_info))
|
||||||
|
if blksize then
|
||||||
|
eq(blksize, fs.os_fileinfo_blocksize(file_info))
|
||||||
|
else
|
||||||
|
-- luafs dosn't support blksize on windows
|
||||||
|
-- libuv on windows returns a constant value as blocksize
|
||||||
|
-- checking for this constant value should be enough
|
||||||
|
eq(2048, fs.os_fileinfo_blocksize(file_info))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe('os_fileid', function()
|
||||||
it('returns false if given an non-existing file', function()
|
it('returns false if given an non-existing file', function()
|
||||||
local file_id = file_id_new()
|
local file_id = file_id_new()
|
||||||
assert.is_false((fs.os_get_file_id('/non-existent', file_id)))
|
assert.is_false((fs.os_fileid('/non-existent', file_id)))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('returns true if given an existing file and fills file_id', function()
|
it('returns true if given an existing file and fills file_id', function()
|
||||||
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_id(path, file_id)))
|
assert.is_true((fs.os_fileid(path, file_id)))
|
||||||
assert.is_true(0 < file_id[0].inode)
|
assert.is_true(0 < file_id[0].inode)
|
||||||
assert.is_true(0 < file_id[0].device_id)
|
assert.is_true(0 < file_id[0].device_id)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('os_file_id_equal', function()
|
describe('os_fileid_equal', function()
|
||||||
it('returns true if two FileIDs are equal', function()
|
it('returns true if two FileIDs are equal', function()
|
||||||
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_id(path, file_id)))
|
assert.is_true((fs.os_fileid(path, file_id)))
|
||||||
assert.is_true((fs.os_file_id_equal(file_id, file_id)))
|
assert.is_true((fs.os_fileid_equal(file_id, file_id)))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('returns false if two FileIDs are not equal', function()
|
it('returns false if two FileIDs are not equal', function()
|
||||||
@@ -625,20 +674,20 @@ describe('fs function', function()
|
|||||||
local file_id_2 = file_id_new()
|
local file_id_2 = file_id_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_id(path_1, file_id_1)))
|
assert.is_true((fs.os_fileid(path_1, file_id_1)))
|
||||||
assert.is_true((fs.os_get_file_id(path_2, file_id_2)))
|
assert.is_true((fs.os_fileid(path_2, file_id_2)))
|
||||||
assert.is_false((fs.os_file_id_equal(file_id_1, file_id_2)))
|
assert.is_false((fs.os_fileid_equal(file_id_1, file_id_2)))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('os_file_id_equal_file_info', function()
|
describe('os_fileid_equal_fileinfo', function()
|
||||||
it('returns true if file_id and file_info represent the same file', function()
|
it('returns true if file_id and file_info represent the same file', function()
|
||||||
local file_id = file_id_new()
|
local file_id = file_id_new()
|
||||||
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_fileid(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_fileid_equal_fileinfo(file_id, file_info)))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('returns false if file_id and file_info represent different files', function()
|
it('returns false if file_id and file_info represent different files', function()
|
||||||
@@ -646,9 +695,9 @@ describe('fs function', function()
|
|||||||
local file_info = file_info_new()
|
local file_info = 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_id(path_1, file_id)))
|
assert.is_true((fs.os_fileid(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_fileid_equal_fileinfo(file_id, file_info)))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user