diff --git a/src/fs_clonefile.cpp b/src/fs_clonefile.cpp index 48707ae2..8180f325 100644 --- a/src/fs_clonefile.cpp +++ b/src/fs_clonefile.cpp @@ -27,6 +27,7 @@ #include "fs_attr.hpp" #include "fs_fallocate.hpp" #include "fs_sendfile.hpp" +#include "fs_time.hpp" #include "fs_xattr.hpp" using std::string; @@ -168,10 +169,7 @@ namespace fs if(rv == -1) return -1; - struct timespec times[2]; - times[0] = stin.st_atim; - times[1] = stin.st_mtim; - rv = ::futimens(fdout,times); + rv = fs::utimes(fdout,stin); if(rv == -1) return -1; diff --git a/src/fs_time.cpp b/src/fs_time.cpp new file mode 100644 index 00000000..a8267d5f --- /dev/null +++ b/src/fs_time.cpp @@ -0,0 +1,21 @@ +/* + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifdef __linux__ +# include "fs_time_futimens.icpp" +#else +# include "fs_time_futimes.icpp" +#endif diff --git a/src/fs_time.hpp b/src/fs_time.hpp new file mode 100644 index 00000000..d79222d5 --- /dev/null +++ b/src/fs_time.hpp @@ -0,0 +1,22 @@ +/* + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +namespace fs +{ + int + utimes(const int fd, + const struct stat &st); +} diff --git a/src/fs_time_futimens.icpp b/src/fs_time_futimens.icpp new file mode 100644 index 00000000..529140a0 --- /dev/null +++ b/src/fs_time_futimens.icpp @@ -0,0 +1,33 @@ +/* + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include +#include + +namespace fs +{ + int + utimes(const int fd, + const struct stat &st) + { + struct timespec times[2]; + + times[0] = st.st_atim; + times[1] = st.st_mtim; + + return ::futimens(fd,times); + } +} diff --git a/src/fs_time_futimes.icpp b/src/fs_time_futimes.icpp new file mode 100644 index 00000000..d4019b89 --- /dev/null +++ b/src/fs_time_futimes.icpp @@ -0,0 +1,33 @@ +/* + Copyright (c) 2016, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include +#include + +namespace fs +{ + int + utimes(const int fd, + const struct stat &st) + { + struct timeval times[2]; + + TIMESPEC_TO_TIMEVAL(×[0],&st.st_atimespec); + TIMESPEC_TO_TIMEVAL(×[1],&st.st_mtimespec); + + return ::futimes(fd,times); + } +}