IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 2, 2009, 3:05:47 PM (18 years ago)
Author:
eugene
Message:

check and retry for existence of containing directory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/fits/psFits.c

    r19035 r21081  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2008-08-12 22:54:53 $
     9 *  @version $Revision: 1.82 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2009-01-03 01:05:47 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2020#include <string.h>
    2121#include <errno.h>
     22#include <libgen.h>
    2223
    2324#include "psFits.h"
     
    123124}
    124125
     126# define FITS_OPEN_RETRIES 5
     127# define FITS_OPEN_RETRY_WAIT 200000
     128
    125129psFits* psFitsOpen(const char* name, const char* mode)
    126130{
     
    129133    int status = 0;
    130134    fitsfile *fptr = NULL;      /* Pointer to the FITS file */
     135
     136    // check that the directory exists : for NFS-mounted file systems, the directory may
     137    // take some time to appear
     138
     139    int dirstat = 0;
     140    char *tmpname = psStringCopy (name);
     141    char *tmpdir = dirname (tmpname);
     142    char *dir = psStringCopy (tmpdir);
     143    useconds_t waittime = FITS_OPEN_RETRY_WAIT;
     144   
     145    for (int i = 0; (i < FITS_OPEN_RETRIES) && ((dirstat = access (dir, F_OK)) != 0); i++) {
     146        // if the error is not ENOENT, then the error is more serious than NFS-mount delays
     147        if (errno != ENOENT) {
     148            int thisErrno = errno;
     149            char errorBuf[64], *errorMsg;
     150# if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
     151            errorMsg = strerror_r (thisErrno, errorBuf, 64);
     152# else
     153            strerror_r (thisErrno, errorBuf, 64);
     154            errorMsg = errorBuf;               
     155# endif
     156            psError (PS_ERR_IO, true, "Directory (%s) for requested file is not accessible: %s", dir, errorMsg);
     157
     158            psFree (dir);
     159            psFree (tmpname);
     160            return NULL;
     161        }
     162
     163        usleep (waittime);
     164        waittime *= 2;
     165    }
     166    if (dirstat != 0) {
     167        psError (PS_ERR_IO, true, "Directory (%s) for requested file is not accessible, timed out", dir);
     168        psFree (dir);
     169        psFree (tmpname);
     170        return NULL;
     171    }
     172    psFree (dir);
     173    psFree (tmpname);
    131174
    132175    /* check the mode to determine how to open/create file */
     
    154197
    155198    if (newFile) {
    156         /* Check if an existing file is in the way before creating file*/
     199        /* Check if an existing file is in the way before creating file */
    157200        if (access(name, F_OK) == 0) {
    158201            // file exists, delete old one first
Note: See TracChangeset for help on using the changeset viewer.