Changeset 7eba9008c5a57a90048772adb5e37be4327d309a
- Timestamp:
- 12/12/07 21:22:32
(10 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1197490952 +0000
- git-parent:
[b25337f62a87919e1c9173d85338903d8745ac9d]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1197490952 +0000
- Message:
Handle I/O errors while writing the cache file
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| re1c8708 |
r7eba900 |
|
| 76 | 76 | #ifdef HAVE_DYNAMIC_PLUGINS |
|---|
| 77 | 77 | static int CacheLoadConfig ( module_t *, FILE * ); |
|---|
| 78 | | static void CacheSaveConfig ( module_t *, FILE * ); |
|---|
| | 78 | static int CacheSaveConfig ( module_t *, FILE * ); |
|---|
| 79 | 79 | static char * CacheName ( void ); |
|---|
| 80 | 80 | |
|---|
| … | … | |
| 452 | 452 | int i, j, i_cache; |
|---|
| 453 | 453 | module_cache_t **pp_cache; |
|---|
| 454 | | int32_t i_file_size = 0; |
|---|
| | 454 | uint32_t i_file_size = 0; |
|---|
| 455 | 455 | libvlc_global_data_t *p_libvlc_global = vlc_global(); |
|---|
| 456 | 456 | |
|---|
| … | … | |
| 458 | 458 | if( !psz_cachedir ) /* XXX: this should never happen */ |
|---|
| 459 | 459 | { |
|---|
| 460 | | msg_Err( p_this, "Unable to get cache directory" ); |
|---|
| | 460 | msg_Err( p_this, "unable to get cache directory" ); |
|---|
| 461 | 461 | return; |
|---|
| 462 | 462 | } |
|---|
| … | … | |
| 468 | 468 | "%s"DIR_SEP"CACHEDIR.TAG", psz_cachedir ); |
|---|
| 469 | 469 | file = utf8_fopen( psz_filename, "wb" ); |
|---|
| 470 | | if( file ) |
|---|
| 471 | | { |
|---|
| 472 | | fwrite( psz_tag, 1, strlen(psz_tag), file ); |
|---|
| | 470 | if (file != NULL) |
|---|
| | 471 | { |
|---|
| | 472 | if (fwrite (psz_tag, 1, sizeof (psz_tag) - 1, file) != 1) |
|---|
| | 473 | clearerr (file); /* what else can we do? */ |
|---|
| 473 | 474 | fclose( file ); |
|---|
| 474 | 475 | } |
|---|
| … | … | |
| 476 | 477 | snprintf( psz_filename, sizeof( psz_filename ), |
|---|
| 477 | 478 | "%s"DIR_SEP"%s", psz_cachedir, CacheName() ); |
|---|
| 478 | | msg_Dbg( p_this, "saving plugins cache file %s", psz_filename ); |
|---|
| | 479 | msg_Dbg( p_this, "writing plugins cache %s", psz_filename ); |
|---|
| 479 | 480 | |
|---|
| 480 | 481 | file = utf8_fopen( psz_filename, "wb" ); |
|---|
| 481 | | if( !file ) |
|---|
| 482 | | { |
|---|
| 483 | | msg_Warn( p_this, "could not open plugins cache file %s for writing", |
|---|
| 484 | | psz_filename ); |
|---|
| 485 | | return; |
|---|
| 486 | | } |
|---|
| | 482 | if (file == NULL) |
|---|
| | 483 | goto error; |
|---|
| 487 | 484 | |
|---|
| 488 | 485 | /* Empty space for file size */ |
|---|
| 489 | | fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file ); |
|---|
| | 486 | if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1) |
|---|
| | 487 | goto error; |
|---|
| 490 | 488 | |
|---|
| 491 | 489 | /* Contains version number */ |
|---|
| 492 | | fprintf( file, "%s", "cache " COPYRIGHT_MESSAGE ); |
|---|
| | 490 | if (fputs ("cache "COPYRIGHT_MESSAGE, file) == EOF) |
|---|
| | 491 | goto error; |
|---|
| 493 | 492 | |
|---|
| 494 | 493 | /* Sub-version number (to avoid breakage in the dev version when cache |
|---|
| 495 | 494 | * structure changes) */ |
|---|
| 496 | 495 | i_file_size = CACHE_SUBVERSION_NUM; |
|---|
| 497 | | fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file ); |
|---|
| | 496 | if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1 ) |
|---|
| | 497 | goto error; |
|---|
| 498 | 498 | |
|---|
| 499 | 499 | /* Language */ |
|---|
| 500 | | fprintf( file, "%5.5s", _("C") ); |
|---|
| | 500 | if (fprintf (file, "%5.5s", _("C")) == EOF) |
|---|
| | 501 | goto error; |
|---|
| 501 | 502 | |
|---|
| 502 | 503 | /* Header marker */ |
|---|
| 503 | 504 | i_file_size = ftell( file ); |
|---|
| 504 | | fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file ); |
|---|
| | 505 | if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1) |
|---|
| | 506 | goto error; |
|---|
| 505 | 507 | |
|---|
| 506 | 508 | i_cache = p_libvlc_global->p_module_bank->i_cache; |
|---|
| 507 | 509 | pp_cache = p_libvlc_global->p_module_bank->pp_cache; |
|---|
| 508 | 510 | |
|---|
| 509 | | fwrite( &i_cache, sizeof(char), sizeof(i_cache), file ); |
|---|
| 510 | | |
|---|
| 511 | | #define SAVE_IMMEDIATE(a) \ |
|---|
| 512 | | fwrite( &a, sizeof(char), sizeof(a), file ) |
|---|
| 513 | | #define SAVE_STRING(a) \ |
|---|
| 514 | | { i_size = a ? strlen( a ) + 1 : 0; \ |
|---|
| 515 | | fwrite( &i_size, sizeof(char), sizeof(i_size), file ); \ |
|---|
| 516 | | if( a ) fwrite( a, sizeof(char), i_size, file ); \ |
|---|
| | 511 | if (fwrite( &i_cache, sizeof (i_cache), 1, file) != 1) |
|---|
| | 512 | goto error; |
|---|
| | 513 | |
|---|
| | 514 | #define SAVE_IMMEDIATE( a ) \ |
|---|
| | 515 | if (fwrite (&a, sizeof(a), 1, file) != 1) \ |
|---|
| | 516 | goto error |
|---|
| | 517 | #define SAVE_STRING( a ) \ |
|---|
| | 518 | { \ |
|---|
| | 519 | uint16_t i_size = (a != NULL) ? (strlen (a) + 1) : 0; \ |
|---|
| | 520 | if ((fwrite (&i_size, sizeof (i_size), 1, file) != 1) \ |
|---|
| | 521 | || (a && (fwrite (a, 1, i_size, file) != i_size))) \ |
|---|
| | 522 | goto error; \ |
|---|
| 517 | 523 | } while(0) |
|---|
| 518 | 524 | |
|---|
| 519 | 525 | for( i = 0; i < i_cache; i++ ) |
|---|
| 520 | 526 | { |
|---|
| 521 | | uint16_t i_size; |
|---|
| 522 | 527 | uint32_t i_submodule; |
|---|
| 523 | 528 | |
|---|
| … | … | |
| 547 | 552 | |
|---|
| 548 | 553 | /* Config stuff */ |
|---|
| 549 | | CacheSaveConfig( pp_cache[i]->p_module, file ); |
|---|
| | 554 | if (CacheSaveConfig (pp_cache[i]->p_module, file)) |
|---|
| | 555 | goto error; |
|---|
| 550 | 556 | |
|---|
| 551 | 557 | SAVE_STRING( pp_cache[i]->p_module->psz_filename ); |
|---|
| … | … | |
| 579 | 585 | i_file_size = ftell( file ); |
|---|
| 580 | 586 | fseek( file, 0, SEEK_SET ); |
|---|
| 581 | | fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file ); |
|---|
| 582 | | |
|---|
| 583 | | fclose( file ); |
|---|
| | 587 | if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1) |
|---|
| | 588 | goto error; |
|---|
| | 589 | |
|---|
| | 590 | if (fclose (file) == 0) |
|---|
| | 591 | return; /* success! */ |
|---|
| | 592 | |
|---|
| | 593 | file = NULL; |
|---|
| | 594 | error: |
|---|
| | 595 | msg_Warn (p_this, "could not write plugins cache %s (%m)", |
|---|
| | 596 | psz_filename); |
|---|
| | 597 | if (file != NULL) |
|---|
| | 598 | { |
|---|
| | 599 | clearerr (file); |
|---|
| | 600 | fclose (file); |
|---|
| | 601 | } |
|---|
| 584 | 602 | } |
|---|
| 585 | 603 | |
|---|
| 586 | | static void CacheSaveConfig( module_t *p_module, FILE *file ) |
|---|
| | 604 | static int CacheSaveConfig( module_t *p_module, FILE *file ) |
|---|
| 587 | 605 | { |
|---|
| 588 | 606 | uint32_t i_lines = p_module->confsize; |
|---|
| 589 | | uint16_t i_size; |
|---|
| 590 | 607 | |
|---|
| 591 | 608 | SAVE_IMMEDIATE( p_module->i_config_items ); |
|---|
| … | … | |
| 630 | 647 | SAVE_IMMEDIATE( p_module->p_config[i].pf_callback ); |
|---|
| 631 | 648 | } |
|---|
| | 649 | return 0; |
|---|
| | 650 | |
|---|
| | 651 | error: |
|---|
| | 652 | return -1; |
|---|
| 632 | 653 | } |
|---|
| 633 | 654 | |
|---|