Skip to content

Commit f3033c2

Browse files
committed
refs #146, added EINTR handling to directory iteration and file copying
1 parent 4041174 commit f3033c2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

include/ghc/filesystem.hpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3965,14 +3965,24 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options
39653965
return false;
39663966
}
39673967
ssize_t br, bw;
3968-
while ((br = ::read(in, buffer.data(), buffer.size())) > 0) {
3968+
while (true) {
3969+
do { br = ::read(in, buffer.data(), buffer.size()); } while(errno == EINTR);
3970+
if(!br) {
3971+
break;
3972+
}
3973+
if(br < 0) {
3974+
ec = detail::make_system_error();
3975+
::close(in);
3976+
::close(out);
3977+
return false;
3978+
}
39693979
ssize_t offset = 0;
39703980
do {
39713981
if ((bw = ::write(out, buffer.data() + offset, static_cast<size_t>(br))) > 0) {
39723982
br -= bw;
39733983
offset += bw;
39743984
}
3975-
else if (bw < 0) {
3985+
else if (bw < 0 && errno != EINTR) {
39763986
ec = detail::make_system_error();
39773987
::close(in);
39783988
::close(out);
@@ -5673,7 +5683,7 @@ class directory_iterator::impl
56735683
, _entry(nullptr)
56745684
{
56755685
if (!path.empty()) {
5676-
_dir = ::opendir(path.native().c_str());
5686+
do { _dir = ::opendir(path.native().c_str()); } while(errno == EINTR);
56775687
if (!_dir) {
56785688
auto error = errno;
56795689
_base = filesystem::path();
@@ -5700,7 +5710,7 @@ class directory_iterator::impl
57005710
do {
57015711
skip = false;
57025712
errno = 0;
5703-
_entry = ::readdir(_dir);
5713+
do { _entry = ::readdir(_dir); } while(errno == EINTR);
57045714
if (_entry) {
57055715
_dir_entry._path = _base;
57065716
_dir_entry._path.append_name(_entry->d_name);
@@ -5714,7 +5724,7 @@ class directory_iterator::impl
57145724
::closedir(_dir);
57155725
_dir = nullptr;
57165726
_dir_entry._path.clear();
5717-
if (errno) {
5727+
if (errno && errno != EINTR) {
57185728
ec = detail::make_system_error();
57195729
}
57205730
break;

0 commit comments

Comments
 (0)