diff --git a/ChangeLog b/ChangeLog index 00c64e726..1657f2435 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * fix permissions issue on linux whith noatime enabled for non-owned files * use random peer IDs in anonymous mode * fix move_storage bugs * fix unnecessary dependency on boost.date_time when building boost.asio as separate compilation diff --git a/src/file.cpp b/src/file.cpp index 68b0a4af6..9bbefb46c 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -980,9 +980,27 @@ namespace libtorrent { mode &= ~no_buffer; m_fd = ::open(path.c_str() - , mode & (rw_mask | no_buffer), permissions); - } + , mode_array[mode & rw_mask] +#ifdef O_NOATIME + | no_atime_flag[(mode & no_atime) >> 4] +#endif + , permissions); + } +#endif + +#ifdef O_NOATIME + // O_NOATIME is not allowed for files we don't own + // so, if we get EPERM when we try to open with it + // try again without O_NOATIME + if (m_fd == -1 && (mode & no_atime) && errno == EPERM) + { + mode &= ~no_atime; + m_fd = ::open(path.c_str() + , mode_array[mode & rw_mask] + | no_buffer_flag[(mode & no_buffer) >> 2] + , permissions); + } #endif if (m_fd == -1) {