diff --git a/ultra-cp/ultra-cp.c b/ultra-cp/ultra-cp.c index d8a31d8cc8a7e1aa6b62fd853187a9d8660a5a23..48e86031f105033abc4a7934c66281fc6332884f 100644 --- a/ultra-cp/ultra-cp.c +++ b/ultra-cp/ultra-cp.c @@ -27,6 +27,11 @@ int get_int_permissions(const char *path) { */ void copy_entry(struct dirent *entry, const char *source, const char *destination) { + struct stat entry_stat; + + if (stat(source, &entry_stat) < 0) + return; + // Entry is a file, copy it if (entry->d_type == DT_REG) { FILE *src_file, *dst_file; @@ -47,6 +52,12 @@ void copy_entry(struct dirent *entry, const char *source, // Go deeper if directory if (entry->d_type == DT_DIR) 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); } /** diff --git a/ultra-cp/ultra-cp.h b/ultra-cp/ultra-cp.h index 8f3878abcd846c9fad77f22497c63c05dffbd760..28e2c4483c9e5a8b7f0cefce7ec7add6205ea531 100644 --- a/ultra-cp/ultra-cp.h +++ b/ultra-cp/ultra-cp.h @@ -11,6 +11,7 @@ #include <sys/types.h> #include <time.h> #include <unistd.h> +#include <utime.h> /** * @brief Get the given file permissions