bootsnap 1.1.6.beta → 1.1.6.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 784acf6d2a96507d9de9157b756638da8b7608a0
4
- data.tar.gz: 512ef099f20aaa5a15c06d4da67f2c4f6db066f2
3
+ metadata.gz: 269514b76977fe302e8e8bed9059ead9a2c9cf28
4
+ data.tar.gz: a66fd4b75f0b4fb211b998ded43f87aa31edc8b4
5
5
  SHA512:
6
- metadata.gz: cd76edbe3f2f62313dbfe86c3d0b4c661cff63c5e735d43992e59be9b08c86d11e1379f54c1dbc6b87b5355e29201f2e9c5431459fb078ed392778065783f52d
7
- data.tar.gz: cfab4dfe53c4baffd3e46a939ceb07eff285f4b0a607df521f7f0b20ea9f66284a32eade3732ed12decd10c11c1c561664d32ba4230db8b4ae8d9fb46655f113
6
+ metadata.gz: e3651625736c73f66e3380c5ca1514769707d5d605541a6f636c9fbb563cc2b3199bfc5baa26130106a158f02f66485bdd606f7db5ee47914e451a7ff4337f0d
7
+ data.tar.gz: e0ba55c3d695a8d91b4ba2aa0ca120ba530c7a665e66a882b8f1e966e846639399e5ea49cecc08aec7ba36b1329b08c84140e20f3aa34efa2902e4b35ebc0681
data/dev.yml CHANGED
@@ -5,5 +5,6 @@ up:
5
5
  - ruby: 2.3.3
6
6
  - bundler
7
7
  commands:
8
+ build: rake compile
8
9
  test: 'rake compile && exec bin/testunit'
9
10
  style: 'exec rubocop -D'
@@ -92,8 +92,8 @@ static void bs_cache_path(const char * cachedir, const char * path, char ** cach
92
92
  static int bs_read_key(int fd, struct bs_cache_key * key);
93
93
  static int cache_key_equal(struct bs_cache_key * k1, struct bs_cache_key * k2);
94
94
  static VALUE bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler);
95
- static int open_current_file(char * path, struct bs_cache_key * key);
96
- static int fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE * output_data, int * exception_tag);
95
+ static int open_current_file(char * path, struct bs_cache_key * key, char ** errno_provenance);
96
+ static int fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE * output_data, int * exception_tag, char ** errno_provenance);
97
97
  static VALUE prot_exception_for_errno(VALUE err);
98
98
  static uint32_t get_os_version(void);
99
99
 
@@ -279,18 +279,22 @@ bs_rb_fetch(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler)
279
279
  * was loaded.
280
280
  */
281
281
  static int
282
- open_current_file(char * path, struct bs_cache_key * key)
282
+ open_current_file(char * path, struct bs_cache_key * key, char ** errno_provenance)
283
283
  {
284
284
  struct stat statbuf;
285
285
  int fd;
286
286
 
287
287
  fd = open(path, O_RDONLY);
288
- if (fd < 0) return fd;
288
+ if (fd < 0) {
289
+ *errno_provenance = (char *)"bs_fetch:open_current_file:open";
290
+ return fd;
291
+ }
289
292
  #ifdef _WIN32
290
293
  setmode(fd, O_BINARY);
291
294
  #endif
292
295
 
293
296
  if (fstat(fd, &statbuf) < 0) {
297
+ *errno_provenance = (char *)"bs_fetch:open_current_file:fstat";
294
298
  close(fd);
295
299
  return -1;
296
300
  }
@@ -336,12 +340,13 @@ bs_read_key(int fd, struct bs_cache_key * key)
336
340
  * - ERROR_WITH_ERRNO (-1, errno is set)
337
341
  */
338
342
  static int
339
- open_cache_file(const char * path, struct bs_cache_key * key)
343
+ open_cache_file(const char * path, struct bs_cache_key * key, char ** errno_provenance)
340
344
  {
341
345
  int fd, res;
342
346
 
343
347
  fd = open(path, O_RDONLY);
344
348
  if (fd < 0) {
349
+ *errno_provenance = (char *)"bs_fetch:open_cache_file:open";
345
350
  if (errno == ENOENT) return CACHE_MISSING_OR_INVALID;
346
351
  return ERROR_WITH_ERRNO;
347
352
  }
@@ -351,6 +356,7 @@ open_cache_file(const char * path, struct bs_cache_key * key)
351
356
 
352
357
  res = bs_read_key(fd, key);
353
358
  if (res < 0) {
359
+ *errno_provenance = (char *)"bs_fetch:open_cache_file:read";
354
360
  close(fd);
355
361
  return res;
356
362
  }
@@ -374,7 +380,7 @@ open_cache_file(const char * path, struct bs_cache_key * key)
374
380
  * or exception, will be the final data returnable to the user.
375
381
  */
376
382
  static int
377
- fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE * output_data, int * exception_tag)
383
+ fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE * output_data, int * exception_tag, char ** errno_provenance)
378
384
  {
379
385
  char * data = NULL;
380
386
  ssize_t nread;
@@ -383,6 +389,7 @@ fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE * output_data,
383
389
  VALUE storage_data;
384
390
 
385
391
  if (data_size > 100000000000) {
392
+ *errno_provenance = (char *)"bs_fetch:fetch_cached_data:datasize";
386
393
  errno = EINVAL; /* because wtf? */
387
394
  ret = -1;
388
395
  goto done;
@@ -390,6 +397,7 @@ fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE * output_data,
390
397
  data = ALLOC_N(char, data_size);
391
398
  nread = read(fd, data, data_size);
392
399
  if (nread < 0) {
400
+ *errno_provenance = (char *)"bs_fetch:fetch_cached_data:read";
393
401
  ret = -1;
394
402
  goto done;
395
403
  }
@@ -441,12 +449,12 @@ mkpath(char * file_path, mode_t mode)
441
449
  * path.
442
450
  */
443
451
  static int
444
- atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data)
452
+ atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data, char ** errno_provenance)
445
453
  {
446
454
  char template[MAX_CACHEPATH_SIZE + 20];
447
455
  char * dest;
448
456
  char * tmp_path;
449
- int fd;
457
+ int fd, ret;
450
458
  ssize_t nwrite;
451
459
 
452
460
  dest = strncpy(template, path, MAX_CACHEPATH_SIZE);
@@ -455,9 +463,15 @@ atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data)
455
463
  tmp_path = mktemp(template);
456
464
  fd = open(tmp_path, O_WRONLY | O_CREAT, 0644);
457
465
  if (fd < 0) {
458
- if (mkpath(path, 0755) < 0) return -1;
466
+ if (mkpath(path, 0755) < 0) {
467
+ *errno_provenance = (char *)"bs_fetch:atomic_write_cache_file:mkpath";
468
+ return -1;
469
+ }
459
470
  fd = open(tmp_path, O_WRONLY | O_CREAT, 0644);
460
- if (fd < 0) return -1;
471
+ if (fd < 0) {
472
+ *errno_provenance = (char *)"bs_fetch:atomic_write_cache_file:open";
473
+ return -1;
474
+ }
461
475
  }
462
476
  #ifdef _WIN32
463
477
  setmode(fd, O_BINARY);
@@ -465,8 +479,12 @@ atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data)
465
479
 
466
480
  key->data_size = RSTRING_LEN(data);
467
481
  nwrite = write(fd, key, KEY_SIZE);
468
- if (nwrite < 0) return -1;
482
+ if (nwrite < 0) {
483
+ *errno_provenance = (char *)"bs_fetch:atomic_write_cache_file:write";
484
+ return -1;
485
+ }
469
486
  if (nwrite != KEY_SIZE) {
487
+ *errno_provenance = (char *)"bs_fetch:atomic_write_cache_file:keysize";
470
488
  errno = EIO; /* Lies but whatever */
471
489
  return -1;
472
490
  }
@@ -474,12 +492,17 @@ atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data)
474
492
  nwrite = write(fd, RSTRING_PTR(data), RSTRING_LEN(data));
475
493
  if (nwrite < 0) return -1;
476
494
  if (nwrite != RSTRING_LEN(data)) {
495
+ *errno_provenance = (char *)"bs_fetch:atomic_write_cache_file:writelength";
477
496
  errno = EIO; /* Lies but whatever */
478
497
  return -1;
479
498
  }
480
499
 
481
500
  close(fd);
482
- return rename(tmp_path, path);
501
+ ret = rename(tmp_path, path);
502
+ if (ret < 0) {
503
+ *errno_provenance = (char *)"bs_fetch:atomic_write_cache_file:rename";
504
+ }
505
+ return ret;
483
506
  }
484
507
 
485
508
  /*
@@ -502,10 +525,15 @@ prot_exception_for_errno(VALUE err)
502
525
  /* Read contents from an fd, whose contents are asserted to be +size+ bytes
503
526
  * long, into a buffer */
504
527
  static ssize_t
505
- bs_read_contents(int fd, size_t size, char ** contents)
528
+ bs_read_contents(int fd, size_t size, char ** contents, char ** errno_provenance)
506
529
  {
530
+ ssize_t nread;
507
531
  *contents = ALLOC_N(char, size);
508
- return read(fd, *contents, size);
532
+ nread = read(fd, *contents, size);
533
+ if (nread < 0) {
534
+ *errno_provenance = (char *)"bs_fetch:bs_read_contents:read";
535
+ }
536
+ return nread;
509
537
  }
510
538
 
511
539
  /*
@@ -559,6 +587,7 @@ bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler)
559
587
  char * contents = NULL;
560
588
  int cache_fd = -1, current_fd = -1;
561
589
  int res, valid_cache, exception_tag = 0;
590
+ char * errno_provenance = NULL;
562
591
 
563
592
  VALUE input_data; /* data read from source file, e.g. YAML or ruby source */
564
593
  VALUE storage_data; /* compiled data, e.g. msgpack / binary iseq */
@@ -567,11 +596,11 @@ bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler)
567
596
  VALUE exception; /* ruby exception object to raise instead of returning */
568
597
 
569
598
  /* Open the source file and generate a cache key for it */
570
- current_fd = open_current_file(path, &current_key);
599
+ current_fd = open_current_file(path, &current_key, &errno_provenance);
571
600
  if (current_fd < 0) goto fail_errno;
572
601
 
573
602
  /* Open the cache key if it exists, and read its cache key in */
574
- cache_fd = open_cache_file(cache_path, &cached_key);
603
+ cache_fd = open_cache_file(cache_path, &cached_key, &errno_provenance);
575
604
  if (cache_fd < 0 && cache_fd != CACHE_MISSING_OR_INVALID) goto fail_errno;
576
605
 
577
606
  /* True if the cache existed and no invalidating changes have occurred since
@@ -580,7 +609,10 @@ bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler)
580
609
 
581
610
  if (valid_cache) {
582
611
  /* Fetch the cache data and return it if we're able to load it successfully */
583
- res = fetch_cached_data(cache_fd, (ssize_t)cached_key.data_size, handler, &output_data, &exception_tag);
612
+ res = fetch_cached_data(
613
+ cache_fd, (ssize_t)cached_key.data_size, handler,
614
+ &output_data, &exception_tag, &errno_provenance
615
+ );
584
616
  if (exception_tag != 0) goto raise;
585
617
  else if (res == CACHE_MISSING_OR_INVALID) valid_cache = 0;
586
618
  else if (res == ERROR_WITH_ERRNO) goto fail_errno;
@@ -591,7 +623,7 @@ bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler)
591
623
  /* Cache is stale, invalid, or missing. Regenerate and write it out. */
592
624
 
593
625
  /* Read the contents of the source file into a buffer */
594
- if (bs_read_contents(current_fd, current_key.size, &contents) < 0) goto fail_errno;
626
+ if (bs_read_contents(current_fd, current_key.size, &contents, &errno_provenance) < 0) goto fail_errno;
595
627
  input_data = rb_str_new_static(contents, current_key.size);
596
628
 
597
629
  /* Try to compile the input_data using input_to_storage(input_data) */
@@ -608,7 +640,7 @@ bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler)
608
640
  if (!RB_TYPE_P(storage_data, T_STRING)) goto invalid_type_storage_data;
609
641
 
610
642
  /* Write the cache key and storage_data to the cache directory */
611
- res = atomic_write_cache_file(cache_path, &current_key, storage_data);
643
+ res = atomic_write_cache_file(cache_path, &current_key, storage_data, &errno_provenance);
612
644
  if (res < 0) goto fail_errno;
613
645
 
614
646
  /* Having written the cache, now convert storage_data to output_data */
@@ -618,7 +650,10 @@ bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler)
618
650
  /* If output_data is nil, delete the cache entry and generate the output
619
651
  * using input_to_output */
620
652
  if (NIL_P(output_data)) {
621
- if (unlink(cache_path) < 0) goto fail_errno;
653
+ if (unlink(cache_path) < 0) {
654
+ errno_provenance = (char *)"bs_fetch:unlink";
655
+ goto fail_errno;
656
+ }
622
657
  bs_input_to_output(handler, input_data, &output_data, &exception_tag);
623
658
  if (exception_tag != 0) goto raise;
624
659
  }
@@ -637,6 +672,9 @@ fail_errno:
637
672
  CLEANUP;
638
673
  exception = rb_protect(prot_exception_for_errno, INT2FIX(errno), &res);
639
674
  if (res) exception = rb_eStandardError;
675
+ if (errno_provenance != NULL) {
676
+ exception = rb_exc_new_str(exception, rb_str_new2(errno_provenance));
677
+ }
640
678
  rb_exc_raise(exception);
641
679
  __builtin_unreachable();
642
680
  raise:
@@ -1,3 +1,3 @@
1
1
  module Bootsnap
2
- VERSION = "1.1.6.beta"
2
+ VERSION = "1.1.6.beta2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootsnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6.beta
4
+ version: 1.1.6.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-05 00:00:00.000000000 Z
11
+ date: 2017-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler