Skip to content

Commit 4353187

Browse files
fd00tagomoris
authored andcommitted
Fix extension file permissions on Cygwin in namespace feature
1 parent 957c832 commit 4353187

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

namespace.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ copy_ext_file_error(char *message, size_t size, int copy_retvalue, char *src_pat
510510
snprintf(message, size, "failed to read the extension path: %s", src_path);
511511
case 4:
512512
snprintf(message, size, "failed to write the extension path: %s", dst_path);
513+
case 5:
514+
snprintf(message, size, "failed to stat the extension path to copy permissions: %s", src_path);
515+
case 6:
516+
snprintf(message, size, "failed to set permissions to the copied extension path: %s", dst_path);
513517
default:
514518
rb_bug("unknown return value of copy_ext_file: %d", copy_retvalue);
515519
}
@@ -585,6 +589,19 @@ copy_ext_file(char *src_path, char *dst_path)
585589
}
586590
fclose(src);
587591
fclose(dst);
592+
#if defined(__CYGWIN__)
593+
// On Cygwin, CopyFile-like operations may strip executable bits.
594+
// Explicitly match destination file permissions to source.
595+
if (retvalue == 0) {
596+
struct stat st;
597+
if (stat(src_path, &st) != 0) {
598+
retvalue = 5;
599+
}
600+
else if (chmod(dst_path, st.st_mode & 0777) != 0) {
601+
retvalue = 6;
602+
}
603+
}
604+
#endif
588605
return retvalue;
589606
#endif
590607
}

0 commit comments

Comments
 (0)