Changeset 17596 in niluje


Ignore:
Timestamp:
Jul 29, 2020, 5:41:33 AM (2 weeks ago)
Author:
NiLuJe
Message:

MobiCOver:

  • Some more cosmetic tweaks around path handling
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Configs/trunk/Kindle/Touch_Hacks/MobiCover/LibMobi/mobicover.c

    r17595 r17596  
    8181/**
    8282 @brief Parse file name into file path and base name.
    83         Dirname or basename can be skipped by setting to null.
     83        Dirname or basename can be skipped by setting to NULL.
    8484        All buffers must have FILENAME_MAX size.
    8585 @param[in] fullpath Full file path
     
    219219
    220220        char dirname[FILENAME_MAX];
    221         char basename[FILENAME_MAX];
    222         split_fullpath(fullpath, dirname, basename);
     221        split_fullpath(fullpath, dirname, NULL);
    223222
    224223        char* asin   = mobi_meta_get_asin(m);
     
    250249                snprintf(cover_path, sizeof(cover_path), "%s/cover_raw_%s.%s", outdir, cdekey, ext);
    251250        } else {
     251                // NOTE: split_fullpath should mostly guarantee dirname already ends with a /
    252252                snprintf(cover_path, sizeof(cover_path), "%s/cover_raw_%s.%s", dirname, cdekey, ext);
    253253        }
    254254        free(asin);
    255 
    256         fprintf(stderr, "Saving cover to %s\n", cover_path);
     255        // Resolve final path (mainly for cosmetic reasons ;p)
     256        char  abspath[PATH_MAX];
     257        char* p = realpath(cover_path, abspath);
     258        if (p == NULL) {
     259                fprintf(stderr, "Unable to resolve output cover path (realpath: %m)!\n");
     260                return ERRCODE(EXIT_FAILURE);
     261        }
     262
     263        fprintf(stderr, "Saving cover to %s\n", p);
    257264        errno      = 0;
    258         FILE* file = fopen(cover_path, "wb");
     265        FILE* file = fopen(p, "wb");
    259266        if (file == NULL) {
    260                 fprintf(stderr, "Could not open file for writing: %s (fopen: %m)\n", cover_path);
     267                fprintf(stderr, "Could not open file for writing: %s (fopen: %m)\n", p);
    261268                return ERRCODE(EXIT_FAILURE);
    262269        }
    263270        size_t count = fwrite(record->data, 1, record->size, file);
    264271        if (count != record->size) {
    265                 fprintf(stderr, "Error writing to file: %s (fwrite: %m)\n", cover_path);
     272                fprintf(stderr, "Error writing to file: %s (fwrite: %m)\n", p);
    266273                fclose(file);
    267274                return ERRCODE(EXIT_FAILURE);
Note: See TracChangeset for help on using the changeset viewer.