Skip to content
Snippets Groups Projects
Commit 570de6d0 authored by tanguy.cavagna's avatar tanguy.cavagna :desktop:
Browse files

Added time attributes on copy

parent 8133bc4e
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,11 @@ int get_int_permissions(const char *path) { ...@@ -27,6 +27,11 @@ int get_int_permissions(const char *path) {
*/ */
void copy_entry(struct dirent *entry, const char *source, void copy_entry(struct dirent *entry, const char *source,
const char *destination) { const char *destination) {
struct stat entry_stat;
if (stat(source, &entry_stat) < 0)
return;
// Entry is a file, copy it // Entry is a file, copy it
if (entry->d_type == DT_REG) { if (entry->d_type == DT_REG) {
FILE *src_file, *dst_file; FILE *src_file, *dst_file;
...@@ -47,6 +52,12 @@ void copy_entry(struct dirent *entry, const char *source, ...@@ -47,6 +52,12 @@ void copy_entry(struct dirent *entry, const char *source,
// Go deeper if directory // Go deeper if directory
if (entry->d_type == DT_DIR) if (entry->d_type == DT_DIR)
mkdir(destination, get_int_permissions(source)); mkdir(destination, get_int_permissions(source));
struct utimbuf new_time;
new_time.actime = entry_stat.st_atim.tv_sec;
new_time.modtime = entry_stat.st_mtim.tv_sec;
utime(destination, &new_time);
} }
/** /**
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <utime.h>
/** /**
* @brief Get the given file permissions * @brief Get the given file permissions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment