Log manager no longer creates files when checking if they exist.

This commit is contained in:
Markus Makela
2015-02-15 20:10:09 +02:00
parent 691eefe0de
commit 678fbb4646

View File

@ -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,111 +2348,54 @@ 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) if(access(filename,W_OK) == 0)
{ {
/** Open file */ if(writable)
fd = open(filename, O_CREAT|O_RDWR, S_IRWXU|S_IRWXG); {
*writable = true;
if (fd == -1) }
{ }
if (do_log && file_is_symlink(filename)) else
{ {
fprintf(stderr,
"*\n* Error : Can't access " if (do_log && file_is_symlink(filename))
"file pointed to by %s due " {
"to %s.\n", fprintf(stderr,
filename, "*\n* Error : Can't access "
strerror(errno)); "file pointed to by %s due "
} "to %s.\n",
else if (do_log) filename,
{ strerror(errno));
fprintf(stderr, }
"*\n* Error : Can't access %s due " else if (do_log)
"to %s.\n", {
filename, fprintf(stderr,
strerror(errno)); "*\n* Error : Can't access %s due "
} "to %s.\n",
if (writable) filename,
{ strerror(errno));
*writable = false; }
}
} if(writable)
else {
{ *writable = false;
if (writable) }
{ }
if (access(filename,W_OK) == 0)
{ }
*writable = true; else
} {
else exists = false;
{ if(writable)
if (do_log && {
file_is_symlink(filename)) *writable = true;
{ }
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)
{
*writable = false;
}
}
}
else
{
close(fd);
unlink(filename);
exists = false;
if (writable)
{
*writable = true;
}
}
} }
return exists; return exists;
} }