Changeset 18073
- Timestamp:
- Jun 10, 2008, 11:53:09 AM (18 years ago)
- Location:
- trunk/psModules/src/config
- Files:
-
- 2 edited
-
pmConfig.c (modified) (7 diffs)
-
pmConfig.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r18061 r18073 42 42 static bool readCameraConfig = true; // Read the camera config on startup (with pmConfigRead)? 43 43 static psArray *configPath = NULL; // Search path for configuration files 44 45 static bool checkPath(const char *filename, bool create, bool trunc); 44 46 45 47 bool pmConfigReadParamsSet(bool newReadCameraConfig) … … 1490 1492 1491 1493 // convert the supplied name, create a new output psString 1492 psString pmConfigConvertFilename(const char *filename, const pmConfig *config, bool create, bool trunc ate)1494 psString pmConfigConvertFilename(const char *filename, const pmConfig *config, bool create, bool trunc) 1493 1495 { 1494 1496 PS_ASSERT_STRING_NON_EMPTY(filename, NULL); … … 1507 1509 newName = tmpName; 1508 1510 1509 if (!c reate && 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); 1512 1514 return NULL; 1513 1515 } … … 1556 1558 newName = tmpName; 1557 1559 1558 if (!c reate && 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); 1561 1563 return NULL; 1562 1564 } 1565 1563 1566 return newName; 1564 1567 } … … 1596 1599 1597 1600 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); 1609 1614 nebServerFree(server); 1610 1615 return NULL; … … 1616 1621 nebFree(nebfile); 1617 1622 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 } 1618 1631 1619 1632 return path; … … 1694 1707 } 1695 1708 1709 static 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 1696 1744 1697 1745 #if 0 -
trunk/psModules/src/config/pmConfig.h
r18061 r18073 5 5 * @author Eugene Magnier, IfA 6 6 * 7 * @version $Revision: 1.3 7$ $Name: not supported by cvs2svn $8 * @date $Date: 2008-06-10 2 0:28:25$7 * @version $Revision: 1.38 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2008-06-10 21:53:09 $ 9 9 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii 10 10 */ … … 164 164 const pmConfig *config, ///< configuration 165 165 bool create, ///< create the file if it doesn't exist 166 bool trunc ate///< truncate the file (if it exists)166 bool trunc ///< truncate the file (if it exists) 167 167 ); 168 168
Note:
See TracChangeset
for help on using the changeset viewer.
