path: signal last use of the file (touch)

To have a system-level overview of when was the last time the file was
used, update the file modification timestamp to to the current time.

This is needed to remove stale cache files of the system.

Access time is not used as it may be, on the system level, disabled.

Ticket: 7830
pull/14630/head
Lukas Sismis 10 months ago committed by Victor Julien
parent 85f0382072
commit fd3847db72

@ -277,3 +277,23 @@ bool SCPathContainsTraversal(const char *path)
#endif
return strstr(path, pattern) != NULL;
}
/**
* \brief Update access and modification time of an existing file to 'now'.
* \param path The file path to touch
* \retval 0 on success, -1 on failure
*/
int SCTouchFile(const char *path)
{
if (path == NULL || path[0] == '\0') {
errno = EINVAL;
return -1;
}
#ifndef OS_WIN32
struct utimbuf ub;
ub.actime = ub.modtime = time(NULL);
if (utime(path, &ub) == 0)
return 0;
#endif
return -1;
}

@ -59,5 +59,6 @@ bool SCIsRegularFile(const struct dirent *const dir_entry);
char *SCRealPath(const char *path, char *resolved_path);
const char *SCBasename(const char *path);
bool SCPathContainsTraversal(const char *path);
int SCTouchFile(const char *path);
#endif /* SURICATA_UTIL_PATH_H */

Loading…
Cancel
Save