diff options
author | Dirk Grobler <dg@openoffice.org> | 2001-09-18 18:12:17 +0000 |
---|---|---|
committer | Dirk Grobler <dg@openoffice.org> | 2001-09-18 18:12:17 +0000 |
commit | 20c22b99129a4bcefbca6976f9c6329bb7ac7a72 (patch) | |
tree | 4e6654be331c50a90bec1aa787916b3c7a2a9b8a /configmgr | |
parent | 3ac225c65b392558bc4fbd93a0a6b2a3f720a20f (diff) |
#91972# correction of pathhandling, pathhepler replaced by lookup context
Diffstat (limited to 'configmgr')
-rw-r--r-- | configmgr/source/inc/filehelper.hxx | 63 | ||||
-rw-r--r-- | configmgr/source/inc/mergechange.hxx | 7 | ||||
-rw-r--r-- | configmgr/source/misc/filehelper.cxx | 175 | ||||
-rw-r--r-- | configmgr/source/misc/mergechange.cxx | 35 |
4 files changed, 148 insertions, 132 deletions
diff --git a/configmgr/source/inc/filehelper.hxx b/configmgr/source/inc/filehelper.hxx index 21773087fd4a..4491af9af990 100644 --- a/configmgr/source/inc/filehelper.hxx +++ b/configmgr/source/inc/filehelper.hxx @@ -2,9 +2,9 @@ * * $RCSfile: filehelper.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: lla $ $Date: 2001-05-14 12:06:26 $ + * last change: $Author: dg $ $Date: 2001-09-18 19:11:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,31 +70,64 @@ #include <com/sun/star/io/IOException.hpp> #endif +namespace io = com::sun::star::io; + namespace configmgr { + //========================================================================== + //= FileHelper + //========================================================================== + /** Within the FileHelper namespace there is a list of methods declared, which ease + specific file operations. + */ namespace FileHelper { - namespace io = com::sun::star::io; + /// delimiter used in URLs and ConfPath + static const ::sal_Unicode delimiter = sal_Unicode('/'); - // convert a filename like "d:\foo\bar\file.xyz to - // something like file:///d|/foo/bar/file.xyz - rtl::OUString convertFilenameToFileURL(rtl::OUString const& _sFilename); + /// string representation of the delimiter + const rtl::OUString& delimiterAsString(); - void createBackupRemoveAndRename( - const rtl::OUString& _aFromURL, const rtl::OUString &_aToURL) throw (io::IOException); + /// Tests if the file exists. + bool fileExists(rtl::OUString const& _sFileURL); + /// Tests if the directory exists. + bool dirExists(rtl::OUString const& _sDirURL); - void tryToRemoveFile(const rtl::OUString& _aURL) throw (io::IOException); + /** Returns the parent part of the pathname of this File URL, + or an empty string if the name has no parent part. + The parent part is generally everything leading up to the last occurrence + of the separator character. + */ + rtl::OUString getParentDir(rtl::OUString const& _aFileURL); - rtl::OUString createOSLErrorString(osl::FileBase::RC eError); + /** creates a directory whose pathname is specified by a FileURL. + @return true if directory could be created or does exist, otherwise false. + */ + bool mkdir(rtl::OUString const& _sDirURL); + + /** creates a directory whose pathname is specified by a FileURL, + including any necessary parent directories. + @return true if directory (or directories) could be created or do(es) exist, otherwise false. + */ + bool mkdirs(rtl::OUString const& _aDirectory); - bool fileExist(rtl::OUString const& _aFileURL); - bool directoryExist(rtl::OUString const& _aDirexURL); + /** replaces a file specified by _aFromURL with a file specified by _aToURL. + */ + void replaceFile(const rtl::OUString& _aFromURL, const rtl::OUString &_aToURL) throw (io::IOException); - rtl::OUString splitDirectoryOff(rtl::OUString const& _sFilename); - inline const sal_Unicode getFileDelimiter() { return sal_Unicode('/'); } + /** removes a file specified by _aURL. Ignores the case of a non-existing file. + */ + void removeFile(const rtl::OUString& _aURL) throw (io::IOException); + + /** creates an error msg string for a given file error return code. + */ + rtl::OUString createOSLErrorString(osl::FileBase::RC eError); - TimeValue getFileModificationStamp(rtl::OUString const& _aNormalizedFilename) throw (io::IOException); + /** determines the modification time of a directory entry specified by a URL. + @return the TimeValue of the last modification, if the file exists, otherwise a TimeValue(0,0). + */ + TimeValue getModifyTime(rtl::OUString const& _aNormalizedFilename) throw (io::IOException); } } // namespace configmgr diff --git a/configmgr/source/inc/mergechange.hxx b/configmgr/source/inc/mergechange.hxx index a6205ebfd8e4..f1b641adede4 100644 --- a/configmgr/source/inc/mergechange.hxx +++ b/configmgr/source/inc/mergechange.hxx @@ -2,9 +2,9 @@ * * $RCSfile: mergechange.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: jb $ $Date: 2001-07-16 17:00:30 $ + * last change: $Author: dg $ $Date: 2001-09-18 19:11:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -103,6 +103,9 @@ namespace configmgr virtual void handle(SubtreeChange const& _rSubtree); }; + // method that applies changes on a existing subtree + void applyChanges(TreeChangeList & _aTreeChangeList, ISubtree& _aSubtree); + // ----------------------------------------------------------------------------- class OMergeChanges : private ChangeTreeAction, private OPathCreator<RelativePath> { diff --git a/configmgr/source/misc/filehelper.cxx b/configmgr/source/misc/filehelper.cxx index d182bf41131b..0769ff18e268 100644 --- a/configmgr/source/misc/filehelper.cxx +++ b/configmgr/source/misc/filehelper.cxx @@ -2,9 +2,9 @@ * * $RCSfile: filehelper.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: jb $ $Date: 2001-07-30 10:12:48 $ + * last change: $Author: dg $ $Date: 2001-09-18 19:12:17 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -76,159 +76,87 @@ #include <osl/diagnose.h> #endif +#define ASCII(x) rtl::OUString::createFromAscii(x) + namespace configmgr { using namespace ::osl; - namespace io = com::sun::star::io; - -#define ASCII(x) rtl::OUString::createFromAscii(x) -// ----------------------------------------------------------------------------- - rtl::OUString FileHelper::convertFilenameToFileURL(rtl::OUString const& _sFilename) - { - rtl::OUString sURL; - osl::FileBase::getFileURLFromSystemPath( _sFilename, sURL ); + //========================================================================== + //= FileHelper + //========================================================================== - return sURL; + // ----------------------------------------------------------------------------- + const rtl::OUString& FileHelper::delimiterAsString() + { + static const rtl::OUString aStringDelimiter( &FileHelper::delimiter,1); + return aStringDelimiter; } -// ---------------------------- tryToRemoveFile ---------------------------- -void FileHelper::tryToRemoveFile(const rtl::OUString& _aURL) throw (io::IOException) + // ----------------------------------------------------------------------------- + void FileHelper::removeFile(const rtl::OUString& _aURL) throw (io::IOException) { - { - File aFile(_aURL); - FileBase::RC eError = aFile.open(OpenFlag_Read); - if (eError != osl_File_E_None) - { - // IF not exists - return; - } - aFile.close(); - } FileBase::RC eError = File::remove(_aURL); - if (eError != osl_File_E_None) + if (eError != osl_File_E_None && + eError != osl_File_E_NOENT) { rtl::OUString sError = ASCII("tryToRemoveFile: "); sError += FileHelper::createOSLErrorString(eError); sError += ASCII("\n with URL: "); sError += _aURL; -#ifdef DEBUG - rtl::OString aStr = rtl::OUStringToOString(sError,RTL_TEXTENCODING_ASCII_US); - OSL_ENSURE(0, aStr.getStr()); -#endif + OSL_ENSURE(0, rtl::OUStringToOString(sError,RTL_TEXTENCODING_ASCII_US).getStr()); throw io::IOException(sError, NULL); - // return 1; } } -// ----------------------------------------------------------------------------- - void FileHelper::createBackupRemoveAndRename( + // ----------------------------------------------------------------------------- + void FileHelper::replaceFile( const rtl::OUString& _aFromURL, const rtl::OUString &_aToURL) throw (io::IOException) { - // remove FromURL - // rename ToURL to FromURL - FileHelper::tryToRemoveFile(_aFromURL); - + FileHelper::removeFile(_aFromURL); FileBase::RC eError = File::move(_aToURL, _aFromURL); if (eError != osl_File_E_None) { rtl::OUString sError = ASCII("createBackupAndRemove: ") + FileHelper::createOSLErrorString(eError) + ASCII("\n with URL: ") + _aFromURL; -#ifdef DEBUG - rtl::OString aStr = rtl::OUStringToOString(sError,RTL_TEXTENCODING_ASCII_US); - OSL_ENSURE(0, aStr.getStr()); -#endif + OSL_ENSURE(0, rtl::OUStringToOString(sError,RTL_TEXTENCODING_ASCII_US).getStr()); throw io::IOException(sError, NULL); } } -// ----------------------------------------------------------------------------- - bool FileHelper::fileExist(rtl::OUString const& _aFileURL) + + // ----------------------------------------------------------------------------- + bool FileHelper::fileExists(rtl::OUString const& _sFileURL) { DirectoryItem aItem; - FileBase::RC eError = DirectoryItem::get(_aFileURL, aItem); - if (eError != osl_File_E_None) - { - // IF not exists - return false; - } - return true; + return DirectoryItem::get(_sFileURL, aItem) == osl_File_E_None; } // ----------------------------------------------------------------------------- - bool FileHelper::directoryExist(rtl::OUString const& _aDirexURL) + bool FileHelper::dirExists(rtl::OUString const& _sDirURL) { - bool bDirectoryExist; - Directory aDirex(_aDirexURL); - FileBase::RC eError = aDirex.open(); - if (eError != osl_File_E_None) - { - bDirectoryExist = false; - } - else - { - bDirectoryExist = true; - } - - aDirex.close(); - return bDirectoryExist; + return Directory(_sDirURL).open() == osl_File_E_None; } -// ----------------------------------------------------------------------------- - rtl::OUString FileHelper::splitDirectoryOff(rtl::OUString const& _sFilename) - { - // split off the directory - // there is no test, if last string after '/' is a directory, it will cut off - - // evtl. should a test like: check if the last string contain a dot '.' - // help to test it. - - sal_Int32 nIdx = _sFilename.lastIndexOf(FileHelper::getFileDelimiter(), _sFilename.getLength()); - rtl::OUString sDirex = _sFilename.copy(0,nIdx); - return sDirex; - } -// ----------------------------------------------------------------------------- -// return a TimeValue at which time the given file is modified - - TimeValue FileHelper::getFileModificationStamp(rtl::OUString const& _aNormalizedFilename) throw (io::IOException) + // ----------------------------------------------------------------------------- + TimeValue FileHelper::getModifyTime(rtl::OUString const& _sURL) { TimeValue aTime = {0,0}; - DirectoryItem aItem; - osl::FileBase::RC eError = DirectoryItem::get(_aNormalizedFilename, aItem); - if (eError != osl::FileBase::E_None) + if (osl::FileBase::E_None == DirectoryItem::get(_sURL, aItem)) { - rtl::OUString aUStr = FileHelper::createOSLErrorString(eError); - throw io::IOException(aUStr, NULL); - } - - FileStatus aStatus(osl_FileStatus_Mask_ModifyTime|osl_FileStatus_Mask_Type); - eError = aItem.getFileStatus(aStatus); - if (eError != osl::FileBase::E_None) - { - return aTime; - rtl::OUString aUStr = FileHelper::createOSLErrorString(eError); - throw io::IOException(aUStr, NULL); - } - if (aStatus.isValid(osl_FileStatus_Mask_Type)) - { - FileStatus::Type eType = aStatus.getFileType(); - volatile int dummy = 0; - } - - if (aStatus.isValid(osl_FileStatus_Mask_ModifyTime)) - { - aTime = aStatus.getModifyTime(); + FileStatus aStatus(osl_FileStatus_Mask_ModifyTime|osl_FileStatus_Mask_Type); + if (osl::FileBase::E_None == aItem.getFileStatus(aStatus) && aStatus.isValid(osl_FileStatus_Mask_ModifyTime)) + aTime = aStatus.getModifyTime(); } return aTime; } -// ------------------ Create a string from FileBase::RC Error ------------------ + // ----------------------------------------------------------------------------- rtl::OUString FileHelper::createOSLErrorString(FileBase::RC eError) { rtl::OUString aRet; switch(eError) { case osl_File_E_None: - aRet = ASCII(""); break; case osl_File_E_PERM: @@ -410,4 +338,39 @@ void FileHelper::tryToRemoveFile(const rtl::OUString& _aURL) throw (io::IOExcept } return aRet; } + + // ----------------------------------------------------------------------------- + rtl::OUString FileHelper::getParentDir(rtl::OUString const& _sURL) + { + // goto last '/' and cut the rest. + sal_Int32 nIdx = _sURL.lastIndexOf(delimiter, _sURL.getLength()); + if (nIdx > 0) + return _sURL.copy(0, nIdx); + return rtl::OUString(); + } + + // ----------------------------------------------------------------------------- + bool FileHelper::mkdir(rtl::OUString const& _sDirURL) + { + // direct create a directory + osl::FileBase::RC eError = osl::Directory::create(_sDirURL); // try to create the directory + if (eError == osl::FileBase::E_EXIST || + eError == osl::FileBase::E_None || + FileHelper::dirExists(_sDirURL)) return true; // Exists or created + else + return false; + } + + // ----------------------------------------------------------------------------- + bool FileHelper::mkdirs(rtl::OUString const& _sDirURL) + { + bool bRes = mkdir(_sDirURL); + if (!bRes) + { + rtl::OUString sParentDir = FileHelper::getParentDir(_sDirURL); + bRes = (sParentDir.getLength() > 0) && mkdirs(sParentDir) && mkdir(_sDirURL); + } + return bRes; + } + } // namespace configmgr diff --git a/configmgr/source/misc/mergechange.cxx b/configmgr/source/misc/mergechange.cxx index 6c240abac766..74a0acd4fe98 100644 --- a/configmgr/source/misc/mergechange.cxx +++ b/configmgr/source/misc/mergechange.cxx @@ -2,9 +2,9 @@ * * $RCSfile: mergechange.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: jb $ $Date: 2001-07-16 17:00:31 $ + * last change: $Author: dg $ $Date: 2001-09-18 19:12:17 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -574,8 +574,29 @@ namespace configmgr } } // ----------------------------------------------------------------------------- - // in localsession.cxx - void apply(TreeChangeList & _aTreeChangeList, ISubtree& _aSubtree); + void applyChanges(TreeChangeList & _aTreeChangeList, ISubtree& _aSubtree) + { + // coarse: _aSubtree = _aSubtree + _aSubtreeChange; + + TreeUpdate aTreeUpdate(&_aSubtree); + + // pSubtree = pSubtree + aChangeList + TreeChangeList aMergeChangeList(_aTreeChangeList, SubtreeChange::NoChildCopy()); + + OMergeTreeAction aChangeHandler(aMergeChangeList.root, &_aSubtree); + _aTreeChangeList.root.forEachChange(aChangeHandler); + + // now check the real modifications + OChangeActionCounter aChangeCounter; + aChangeCounter.handle(aMergeChangeList.root); + CFG_TRACE_INFO_NI("cache manager: counted changes from notification : additions: %i , removes: %i, value changes: %i", aChangeCounter.nAdds, aChangeCounter.nRemoves, aChangeCounter.nValues); + if (aChangeCounter.hasChanges()) + { + // aTree.updateTree(aMergeChangeList); + aMergeChangeList.root.forEachChange(aTreeUpdate); + } + } + // ----------------------------------------------------------------------------- void OMergeTreeChangeList::handle(SubtreeChange const& _rSubtree) @@ -632,11 +653,7 @@ namespace configmgr // Now apply _rSubtree to the subtree TreeChangeList aChangeList(m_aTreeChangeList.getOptions(), aSubtreePath, Chg(), _rSubtree); // expensive! - apply(aChangeList, *pSubtree); - - // This isn't correct today because _rSubtree is const and this construct require that _rSubtree isn't const - // TreeUpdate aTreeUpdate(pSubtree); - // _rSubtree.applyToChildren(aTreeUpdate); + applyChanges(aChangeList, *pSubtree); } else { |