IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18073


Ignore:
Timestamp:
Jun 10, 2008, 11:53:09 AM (18 years ago)
Author:
jhoblitt
Message:

enable pmConfigConvertFilename()'s truncate argument

Location:
trunk/psModules/src/config
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfig.c

    r18061 r18073  
    4242static bool readCameraConfig = true;    // Read the camera config on startup (with pmConfigRead)?
    4343static psArray *configPath = NULL;      // Search path for configuration files
     44
     45static bool checkPath(const char *filename, bool create, bool trunc);
    4446
    4547bool pmConfigReadParamsSet(bool newReadCameraConfig)
     
    14901492
    14911493// convert the supplied name, create a new output psString
    1492 psString pmConfigConvertFilename(const char *filename, const pmConfig *config, bool create, bool truncate)
     1494psString pmConfigConvertFilename(const char *filename, const pmConfig *config, bool create, bool trunc)
    14931495{
    14941496    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     
    15071509        newName = tmpName;
    15081510
    1509         if (!create && access(newName, R_OK) != 0) {
    1510             psError(PS_ERR_IO, true, "Unable to access file %s", newName);
    1511             psFree(newName);
     1511        if (!checkPath(newName, create, trunc)) {
     1512            // let checkPath()'s psError() call float up
     1513            psFree (newName);
    15121514            return NULL;
    15131515        }
     
    15561558        newName = tmpName;
    15571559
    1558         if (!create && access(newName, R_OK) != 0) {
    1559             psError(PS_ERR_IO, true, "Unable to access file %s", newName);
    1560             psFree(newName);
     1560        if (!checkPath(newName, create, trunc)) {
     1561            // let checkPath()'s psError() call float up
     1562            psFree (newName);
    15611563            return NULL;
    15621564        }
     1565
    15631566        return newName;
    15641567    }
     
    15961599
    15971600        char *nebfile = NULL;
    1598         if (create) {
    1599             nebfile = nebCreate(server, filename, NULL, NULL);
    1600             if (!nebfile) {
    1601                 psError(PM_ERR_SYS, true, "failed to create a new nebulous key: %s", nebErr(server));
    1602                 nebServerFree(server);
    1603                 return NULL;
    1604             }
    1605         } else {
    1606             nebfile = nebFind(server, filename);
    1607             if (!nebfile) {
    1608                 psError(PM_ERR_SYS, true, "failed to find nebulous key: %s", nebErr(server));
     1601        if (!(nebfile = nebFind(server, filename))) {
     1602            // object does not exist
     1603            if (create) {
     1604                nebfile = nebCreate(server, filename, NULL, NULL);
     1605                if (!nebfile) {
     1606                    psError(PM_ERR_SYS, true, "failed to create a new nebulous key: %s", nebErr(server));
     1607                    nebServerFree(server);
     1608                    return NULL;
     1609                }
     1610            } else {
     1611                // if the object does not exist and create isn't set, then we
     1612                // should puke
     1613                psError(PM_ERR_SYS, true, "Unable to access file %s", filename);
    16091614                nebServerFree(server);
    16101615                return NULL;
     
    16161621        nebFree(nebfile);
    16171622        nebServerFree(server);
     1623
     1624        if (trunc) {
     1625            if(truncate(filename, 0) != 0) {
     1626                psError(PS_ERR_IO, true, "Failed to truncate file, %s\n", filename);
     1627                nebServerFree(server);
     1628                return NULL;
     1629            }
     1630        }
    16181631
    16191632        return path;
     
    16941707}
    16951708
     1709static bool checkPath(const char *filename, bool create, bool trunc)
     1710{
     1711    PS_ASSERT_PTR_NON_NULL(filename, false);
     1712
     1713    if (access(filename, R_OK) == 0) {
     1714        // file already exists
     1715        if (trunc) {
     1716            if(truncate(filename, 0) != 0) {
     1717                psError(PS_ERR_IO, true, "Failed to truncate file, %s\n", filename);
     1718                return false;
     1719            }
     1720        }
     1721    } else {
     1722        // file does not exist
     1723        if (create) {
     1724            int fd = open(filename, O_WRONLY|O_CREAT, 0666);
     1725            if (fd == 0) {
     1726                psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename);
     1727                return false;
     1728            }
     1729            if (close(fd) != 0) {
     1730                psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename);
     1731                return false;
     1732            }
     1733        } else {
     1734            // if the file does not exist and create isn't set, then we
     1735            // should puke
     1736            psError(PS_ERR_IO, true, "Unable to access file %s", filename);
     1737            return false;
     1738        }
     1739    }
     1740
     1741    return true;
     1742}
     1743
    16961744
    16971745#if 0
  • trunk/psModules/src/config/pmConfig.h

    r18061 r18073  
    55 *  @author Eugene Magnier, IfA
    66 *
    7  *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2008-06-10 20:28:25 $
     7 *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2008-06-10 21:53:09 $
    99 *  Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    1010 */
     
    164164    const pmConfig *config,             ///< configuration
    165165    bool create,                        ///< create the file if it doesn't exist
    166     bool truncate                       ///< truncate the file (if it exists)
     166    bool trunc                          ///< truncate the file (if it exists)
    167167);
    168168
Note: See TracChangeset for help on using the changeset viewer.