Log manager no longer creates files when checking if they exist.
This commit is contained in:
@ -2335,7 +2335,6 @@ static bool check_file_and_path(
|
|||||||
bool* writable,
|
bool* writable,
|
||||||
bool do_log)
|
bool do_log)
|
||||||
{
|
{
|
||||||
int fd;
|
|
||||||
bool exists;
|
bool exists;
|
||||||
|
|
||||||
if (filename == NULL)
|
if (filename == NULL)
|
||||||
@ -2349,18 +2348,21 @@ static bool check_file_and_path(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fd = open(filename, O_CREAT|O_EXCL, S_IRWXU);
|
if(access(filename,F_OK) == 0)
|
||||||
|
{
|
||||||
|
|
||||||
if (fd == -1)
|
exists = true;
|
||||||
{
|
|
||||||
/** File exists, check permission to read/write */
|
|
||||||
if (errno == EEXIST)
|
|
||||||
{
|
|
||||||
/** Open file */
|
|
||||||
fd = open(filename, O_CREAT|O_RDWR, S_IRWXU|S_IRWXG);
|
|
||||||
|
|
||||||
if (fd == -1)
|
if(access(filename,W_OK) == 0)
|
||||||
{
|
{
|
||||||
|
if(writable)
|
||||||
|
{
|
||||||
|
*writable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
if (do_log && file_is_symlink(filename))
|
if (do_log && file_is_symlink(filename))
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@ -2378,77 +2380,17 @@ static bool check_file_and_path(
|
|||||||
filename,
|
filename,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
if (writable)
|
|
||||||
{
|
|
||||||
*writable = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (writable)
|
|
||||||
{
|
|
||||||
if (access(filename,W_OK) == 0)
|
|
||||||
{
|
|
||||||
*writable = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (do_log &&
|
|
||||||
file_is_symlink(filename))
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"*\n* Error : Can't write to "
|
|
||||||
"file pointed to by %s due to "
|
|
||||||
"%s.\n",
|
|
||||||
filename,
|
|
||||||
strerror(errno));
|
|
||||||
}
|
|
||||||
else if (do_log)
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"*\n* Error : Can't write to "
|
|
||||||
"%s due to %s.\n",
|
|
||||||
filename,
|
|
||||||
strerror(errno));
|
|
||||||
}
|
|
||||||
*writable = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
exists = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (do_log && file_is_symlink(filename))
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"*\n* Error : Can't access the file "
|
|
||||||
"pointed to by %s due to %s.\n",
|
|
||||||
filename,
|
|
||||||
strerror(errno));
|
|
||||||
}
|
|
||||||
else if (do_log)
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"*\n* Error : Can't access %s due to %s.\n",
|
|
||||||
filename,
|
|
||||||
strerror(errno));
|
|
||||||
}
|
|
||||||
exists = false;
|
|
||||||
|
|
||||||
if(writable)
|
if(writable)
|
||||||
{
|
{
|
||||||
*writable = false;
|
*writable = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
close(fd);
|
|
||||||
unlink(filename);
|
|
||||||
exists = false;
|
exists = false;
|
||||||
|
|
||||||
if(writable)
|
if(writable)
|
||||||
{
|
{
|
||||||
*writable = true;
|
*writable = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user