mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2025-03-09 18:01:31 +00:00
Update the access/modification times of the existing file, if there is one, in FileUtils::touch()
This changes FileUtils::touch() to match the documentation for the 'touch' tool on Unix.
This commit is contained in:
parent
d7e3cc8d63
commit
c20c452e98
1 changed files with 12 additions and 4 deletions
|
@ -258,14 +258,22 @@ void FileUtils::touch(const char* path) throw (IOException)
|
||||||
{
|
{
|
||||||
#ifdef PLATFORM_UNIX
|
#ifdef PLATFORM_UNIX
|
||||||
// see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html
|
// see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html
|
||||||
int fd = creat(path,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
if (fileExists(path))
|
||||||
if (fd != -1)
|
|
||||||
{
|
{
|
||||||
close(fd);
|
utimensat(AT_FDCWD,path,0 /* use current date/time */,0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw IOException("Unable to touch file " + std::string(path));
|
int fd = creat(path,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||||
|
if (fd != -1)
|
||||||
|
{
|
||||||
|
futimens(fd,0 /* use current date/time */);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw IOException("Unable to touch file " + std::string(path));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
HANDLE result = CreateFile(path,GENERIC_WRITE,
|
HANDLE result = CreateFile(path,GENERIC_WRITE,
|
||||||
|
|
Loading…
Reference in a new issue