mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-16 10:20:30 +00:00
move stat behind open to cover corner case
This commit is contained in:
parent
3eb77c8302
commit
1f70cace69
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=14244
@ -122,8 +122,7 @@ __hash_open(file, flags, mode, info, dflags)
|
||||
|
||||
new_table = 0;
|
||||
if (!file || (flags & O_TRUNC) ||
|
||||
(stat(file, &statbuf) && (errno == ENOENT)) ||
|
||||
statbuf.st_size == 0) {
|
||||
(stat(file, &statbuf) && (errno == ENOENT))) {
|
||||
if (errno == ENOENT)
|
||||
errno = 0; /* Just in case someone looks at errno */
|
||||
new_table = 1;
|
||||
@ -131,6 +130,13 @@ __hash_open(file, flags, mode, info, dflags)
|
||||
if (file) {
|
||||
if ((hashp->fp = open(file, flags, mode)) == -1)
|
||||
RETURN_ERROR(errno, error0);
|
||||
|
||||
/* if the .db file is empty, and we had permission to create
|
||||
a new .db file, then reinitialize the database */
|
||||
if ((flags & O_CREAT) &&
|
||||
fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0)
|
||||
new_table = 1;
|
||||
|
||||
(void)fcntl(hashp->fp, F_SETFD, 1);
|
||||
}
|
||||
if (new_table) {
|
||||
|
Loading…
Reference in New Issue
Block a user