@@ -96,6 +96,7 @@ static ID instrumentation_method;
96
96
static VALUE sym_hit , sym_miss , sym_stale , sym_revalidated ;
97
97
static bool instrumentation_enabled = false;
98
98
static bool readonly = false;
99
+ static bool perm_issue = false;
99
100
100
101
/* Functions exposed as module functions on Bootsnap::CompileCache::Native */
101
102
static VALUE bs_instrumentation_enabled_set (VALUE self , VALUE enabled );
@@ -119,7 +120,7 @@ static int update_cache_key(struct bs_cache_key *current_key, int cache_fd, cons
119
120
static void bs_cache_key_digest (struct bs_cache_key * key , const VALUE input_data );
120
121
static VALUE bs_fetch (char * path , VALUE path_v , char * cache_path , VALUE handler , VALUE args );
121
122
static VALUE bs_precompile (char * path , VALUE path_v , char * cache_path , VALUE handler );
122
- static int open_current_file (char * path , struct bs_cache_key * key , const char * * errno_provenance );
123
+ static int open_current_file (const char * path , struct bs_cache_key * key , const char * * errno_provenance );
123
124
static int fetch_cached_data (int fd , ssize_t data_size , VALUE handler , VALUE args , VALUE * output_data , int * exception_tag , const char * * errno_provenance );
124
125
static uint32_t get_ruby_revision (void );
125
126
static uint32_t get_ruby_platform (void );
@@ -413,17 +414,34 @@ bs_rb_precompile(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler)
413
414
414
415
return bs_precompile (path , path_v , cache_path , handler );
415
416
}
417
+
418
+ static int bs_open_noatime (const char * path , int flags ) {
419
+ int fd = 1 ;
420
+ if (!perm_issue ) {
421
+ fd = open (path , flags | O_NOATIME );
422
+ if (fd < 0 && errno == EPERM ) {
423
+ errno = 0 ;
424
+ perm_issue = true;
425
+ }
426
+ }
427
+
428
+ if (perm_issue ) {
429
+ fd = open (path , flags );
430
+ }
431
+ return fd ;
432
+ }
433
+
416
434
/*
417
435
* Open the file we want to load/cache and generate a cache key for it if it
418
436
* was loaded.
419
437
*/
420
438
static int
421
- open_current_file (char * path , struct bs_cache_key * key , const char * * errno_provenance )
439
+ open_current_file (const char * path , struct bs_cache_key * key , const char * * errno_provenance )
422
440
{
423
441
struct stat statbuf ;
424
442
int fd ;
425
443
426
- fd = open (path , O_RDONLY | O_NOATIME );
444
+ fd = bs_open_noatime (path , O_RDONLY );
427
445
if (fd < 0 ) {
428
446
* errno_provenance = "bs_fetch:open_current_file:open" ;
429
447
return fd ;
@@ -491,9 +509,9 @@ open_cache_file(const char * path, struct bs_cache_key * key, const char ** errn
491
509
int fd , res ;
492
510
493
511
if (readonly ) {
494
- fd = open (path , O_RDONLY | O_NOATIME );
512
+ fd = bs_open_noatime (path , O_RDONLY );
495
513
} else {
496
- fd = open (path , O_RDWR | O_NOATIME );
514
+ fd = bs_open_noatime (path , O_RDWR );
497
515
}
498
516
499
517
if (fd < 0 ) {
0 commit comments