Skip to content

Commit

Permalink
Fix bug: terminate program if file is not exists (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Zakharov committed Dec 13, 2023
1 parent 41f5baa commit 1ee26f9
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/utils/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1159,24 +1159,35 @@ fio_stat(char const* path, struct stat* st, bool follow_symlink, fio_location lo
bool
fio_is_same_file(char const* filename1, char const* filename2, bool follow_symlink, fio_location location)
{
char *abs_name1 = make_absolute_path(filename1);
char *abs_name2 = make_absolute_path(filename2);
bool result = strcmp(abs_name1, abs_name2) == 0;

#ifndef WIN32
struct stat stat1, stat2;
if (!result)
{
struct stat stat1, stat2;

if (fio_stat(filename1, &stat1, follow_symlink, location) < 0)
elog(ERROR, "Can't stat file \"%s\": %s", filename1, strerror(errno));
if (fio_stat(filename1, &stat1, follow_symlink, location) < 0)
{
if (errno == ENOENT)
return false;
elog(ERROR, "Can't stat file \"%s\": %s", filename1, strerror(errno));
}

if (fio_stat(filename2, &stat2, follow_symlink, location) < 0)
elog(ERROR, "Can't stat file \"%s\": %s", filename2, strerror(errno));
if (fio_stat(filename2, &stat2, follow_symlink, location) < 0)
{
if (errno == ENOENT)
return false;
elog(ERROR, "Can't stat file \"%s\": %s", filename2, strerror(errno));
}

return stat1.st_ino == stat2.st_ino && stat1.st_dev == stat2.st_dev;
#else
char *abs_name1 = make_absolute_path(filename1);
char *abs_name2 = make_absolute_path(filename2);
bool result = strcmp(abs_name1, abs_name2) == 0;
result = (stat1.st_ino == stat2.st_ino && stat1.st_dev == stat2.st_dev);
}
#endif
free(abs_name2);
free(abs_name1);
return result;
#endif
}

/*
Expand Down

0 comments on commit 1ee26f9

Please sign in to comment.