zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #22643
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
Paul J. Lucas has proposed merging lp:~zorba-coders/zorba/bug-1180220 into lp:zorba.
Commit message:
Removed plethora of file classes; moved much of fs_util to the public API to take its place.
Requested reviews:
Paul J. Lucas (paul-lucas)
Related bugs:
Bug #1180220 in Zorba: "Consolidate redundant path/file public APIs"
https://bugs.launchpad.net/zorba/+bug/1180220
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1180220/+merge/167177
Removed plethora of file classes; moved much of fs_util to the public API to take its place.
--
https://code.launchpad.net/~zorba-coders/zorba/bug-1180220/+merge/167177
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'bin/path_util.cpp'
--- bin/path_util.cpp 2013-02-07 17:24:36 +0000
+++ bin/path_util.cpp 2013-06-03 23:16:28 +0000
@@ -16,13 +16,13 @@
#include "path_util.h"
-#include <stdlib.h>
-//#include "zorba/zorba_string.h"
-#include "zorba/util/path.h"
+#include <cstdlib>
+
+#include <zorba/static_context.h>
+#include <zorba/util/fs_util.h>
#include "util.h"
#include "zorbacmdproperties.h"
-#include <zorba/static_context.h>
namespace zorba {
@@ -54,28 +54,28 @@
std::string lPathStr;
// Compute the current working directory to append to all paths.
- filesystem_path lCWD;
+ std::string lCWD( fs::curdir() );
// setModulePaths() *overwrites* the URI path and lib path, so there's no
// sense in calling both. So if --module-path exists, just use it.
aProperties.getModulePath(lPathStr);
if (lPathStr.length() > 0) {
tokenizePath(lPathStr, lPath);
- lPath.push_back(lCWD.get_path());
+ lPath.push_back(lCWD);
aStaticCtx->setModulePaths(lPath);
}
else {
// Compute and set URI path
aProperties.getURIPath(lPathStr);
tokenizePath(lPathStr, lPath);
- lPath.push_back(lCWD.get_path());
+ lPath.push_back(lCWD);
aStaticCtx->setURIPath(lPath);
lPath.clear();
// Compute and set lib path
aProperties.getLibPath(lPathStr);
tokenizePath(lPathStr, lPath);
- lPath.push_back(lCWD.get_path());
+ lPath.push_back(lCWD);
aStaticCtx->setLibPath(lPath);
}
}
=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp 2013-05-28 00:58:27 +0000
+++ bin/zorbacmd.cpp 2013-06-03 23:16:28 +0000
@@ -30,7 +30,6 @@
#endif
#include <zorba/zorba.h>
-#include <zorba/file.h>
#include <zorba/zorba_exception.h>
#include <zorba/xquery_exception.h>
#include <zorba/document_manager.h>
@@ -41,8 +40,8 @@
#include <zorba/serialization_callback.h>
#include <zorba/audit.h>
#include <zorba/audit_scoped.h>
-
#include <zorba/store_manager.h>
+#include <zorba/util/fs_util.h>
//#define DO_AUDIT
@@ -54,9 +53,6 @@
#include "util.h"
#include "path_util.h"
-// For setting the base URI from the current directory
-#include <zorba/util/path.h>
-
// Timing utilities, including wall-clock timing
#include <zorba/util/time.h>
@@ -77,8 +73,6 @@
"Copyright 2006-2009 The FLWOR Foundation.\n"
"License: Apache License 2.0: <http://www.apache.org/licenses/LICENSE-2.0>";
-#define PATH_SEP (zorba::filesystem_path::get_directory_separator ())
-
#ifndef ZORBA_NO_FULL_TEXT
OneToOneURIMapper theStopWordsMapper(EntityData::STOP_WORDS);
OneToOneURIMapper theThesaurusMapper(EntityData::THESAURUS);
@@ -368,13 +362,13 @@
if(str.compare(0, strlen(file3), file3) == 0) {
fpath = str.substr(strlen(file3));
} else if(str.compare(0, strlen(file2), file2) == 0) {
- fpath = PATH_SEP;
+ fpath = fs::dir_separator;
fpath += str.substr(strlen(file2));
}
// replace all slash with backslash
std::string::size_type off=0;
while ((off=fpath.find('/', off)) != std::string::npos)
- fpath.replace(off, 1, PATH_SEP);
+ fpath.replace(off, 1, fs::dir_separator);
return fpath;
#else // for UNIX
@@ -639,14 +633,8 @@
removeOutputFileIfNeeded(const ZorbaCMDProperties& lProperties)
{
#ifdef ZORBA_WITH_FILE_ACCESS
- if (lProperties.outputFile().size() > 0)
- {
- File_t lFile = zorba::File::createFile(lProperties.outputFile());
- if (lFile->exists())
- {
- lFile->remove();
- }
- }
+ if ( !lProperties.outputFile().empty() )
+ fs::remove( lProperties.outputFile(), true );
#endif /* ZORBA_WITH_FILE_ACCESS */
}
@@ -1021,7 +1009,7 @@
std::string configJvmClassPath;
globaproperties->getJVMClassPath(configJvmClassPath);
globaproperties->setJVMClassPath(cmdJvmClassPath +
- filesystem_path::get_path_separator() + configJvmClassPath);
+ fs::path_separator + configJvmClassPath);
// Start the engine
@@ -1068,14 +1056,14 @@
//
std::string fURI = *lIter;
std::string fname = parseFileURI (properties.asFiles (), fURI);
- zorba::filesystem_path path (fname);
- bool asFile = ! fname.empty ();
+ std::string path( fname );
+ bool asFile = !fname.empty();
std::auto_ptr<std::istream> qfile;
if (asFile)
{
- path.resolve_relative ();
- qfile.reset(new std::ifstream (path.c_str ()));
+ fs::make_absolute( path );
+ qfile.reset( new std::ifstream( path.c_str() ) );
}
else
{
@@ -1129,10 +1117,11 @@
{
// No user set base URI. Set the cwd to be used as base-uri in order
// to make the doc function doc("mydoc.xml") work
- zorba::filesystem_path p;
+ std::string p( fs::curdir() );
std::stringstream lTmp;
std::vector<std::string> lTokens;
- Util::tokenize(p.c_str(), PATH_SEP, lTokens);
+ std::string const delim( 1, fs::dir_separator );
+ Util::tokenize(p.c_str(), delim, lTokens);
lTmp << "file://";
for (std::vector<std::string>::const_iterator lIter = lTokens.begin();
@@ -1155,7 +1144,7 @@
zorba::XQuery_t lQuery = lZorbaInstance->createQuery();
if (asFile)
{
- lQuery->setFileName(path.get_path());
+ lQuery->setFileName(path);
}
lQuery->parse (*qfile);
@@ -1178,7 +1167,7 @@
zorba::XQuery_t aQuery = lZorbaInstance->createQuery();
if (asFile)
{
- aQuery->setFileName(path.get_path());
+ aQuery->setFileName(path);
}
aQuery->parse(*qfile);
@@ -1198,7 +1187,7 @@
int status = compileAndExecute(lZorbaInstance,
properties,
lStaticContext,
- path.get_path(),
+ path,
*qfile,
*lOutputStream,
queryTiming);
@@ -1236,7 +1225,7 @@
}
std::auto_ptr<std::istream> lXQ(new std::ifstream(path.c_str()));
- std::string lFileName(path.get_path());
+ std::string lFileName(path);
zorba::XQuery_t lQuery;
=== modified file 'include/zorba/api_shared_types.h'
--- include/zorba/api_shared_types.h 2013-04-10 10:13:31 +0000
+++ include/zorba/api_shared_types.h 2013-06-03 23:16:28 +0000
@@ -16,75 +16,71 @@
#ifndef ZORBA_SHARED_TYPES_INCL_H
#define ZORBA_SHARED_TYPES_INCL_H
-#include <memory>
-
#include <zorba/config.h>
#include <zorba/smart_ptr.h>
namespace zorba {
- class Zorba;
- class XQuery;
- class StaticContext;
- class DynamicContext;
- class XmlDataManager;
- class DocumentManager;
- class CollectionManager;
- class StaticCollectionManager;
- class ItemFactory;
- class Iterator;
- class StatelessExternalFunction;
- class ExternalFunctionParameter;
- class ExternalModule;
- class TypeIdentifier;
- class ItemSequence;
- class Collection;
- class Function;
- class Annotation;
- class SerializationCallback;
- class File;
- class DirectoryIterator;
- class Serializer;
- class ModuleInfo;
-
- class DiagnosticHandler;
- class QueryLocation;
- typedef SmartPtr<QueryLocation> QueryLocation_t;
-
+///////////////////////////////////////////////////////////////////////////////
+
+class Annotation;
+class Collection;
+class CollectionManager;
+class DiagnosticHandler;
+class DocumentManager;
+class DynamicContext;
+class ExternalFunctionParameter;
+class ExternalModule;
+class Function;
+class ItemFactory;
+class ItemSequence;
+class Iterator;
+class ModuleInfo;
+class QueryLocation;
+class SerializationCallback;
+class Serializer;
+class StatelessExternalFunction;
+class StaticCollectionManager;
+class StaticContext;
#ifndef ZORBA_NO_FULL_TEXT
- class StemmerProvider;
- class TokenizerProvider;
+class StemmerProvider;
+class TokenizerProvider;
#endif /* ZORBA_NO_FULL_TEXT */
-
- // smart pointers
- typedef zorba::SmartPtr<XQuery> XQuery_t;
- typedef zorba::SmartPtr<StaticContext> StaticContext_t;
- typedef zorba::SmartPtr<Iterator> Iterator_t;
- typedef zorba::SmartPtr<TypeIdentifier> TypeIdentifier_t;
- typedef zorba::SmartPtr<Collection> Collection_t;
- typedef zorba::SmartPtr<Function> Function_t;
- typedef zorba::SmartPtr<Annotation> Annotation_t;
- typedef zorba::SmartPtr<File> File_t;
- typedef zorba::SmartPtr<DirectoryIterator> DirectoryIterator_t;
- typedef zorba::SmartPtr<Serializer> Serializer_t;
- typedef zorba::SmartPtr<ItemSequence> ItemSequence_t;
- typedef zorba::SmartPtr<ModuleInfo> ModuleInfo_t;
-
- // data handlers
- class Item;
- class String;
-
- // uri resolvers
- class URIMapper;
- class Resource;
- class URLResolver;
-
- namespace audit {
- class Provider;
- class Event;
- class ScopedRecord;
- }
-
-} /* namespace zorba */
-#endif
+class TypeIdentifier;
+class XmlDataManager;
+class XQuery;
+class Zorba;
+
+// smart pointers
+typedef SmartPtr<Annotation> Annotation_t;
+typedef SmartPtr<Collection> Collection_t;
+typedef SmartPtr<Function> Function_t;
+typedef SmartPtr<ItemSequence> ItemSequence_t;
+typedef SmartPtr<Iterator> Iterator_t;
+typedef SmartPtr<ModuleInfo> ModuleInfo_t;
+typedef SmartPtr<QueryLocation> QueryLocation_t;
+typedef SmartPtr<Serializer> Serializer_t;
+typedef SmartPtr<StaticContext> StaticContext_t;
+typedef SmartPtr<TypeIdentifier> TypeIdentifier_t;
+typedef SmartPtr<XQuery> XQuery_t;
+
+// data handlers
+class Item;
+class String;
+
+// uri resolvers
+class URIMapper;
+class Resource;
+class URLResolver;
+
+namespace audit {
+ class Provider;
+ class Event;
+ class ScopedRecord;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+} // namespace zorba
+#endif /* ZORBA_SHARED_TYPES_INCL_H */
/* vim:set et sw=2 ts=2: */
=== modified file 'include/zorba/base64_stream.h'
--- include/zorba/base64_stream.h 2013-02-12 03:55:18 +0000
+++ include/zorba/base64_stream.h 2013-06-03 23:16:28 +0000
@@ -20,6 +20,7 @@
#include <streambuf>
#include <zorba/config.h>
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/streambuf.h>
namespace zorba {
@@ -174,7 +175,7 @@
void detach( std::basic_ios<charT,Traits> &ios ) {
int const index = internal::base64::get_streambuf_index();
if ( streambuf *const buf = static_cast<streambuf*>( ios.pword( index ) ) ) {
- ios.pword( index ) = 0;
+ ios.pword( index ) = nullptr;
ios.rdbuf( buf->orig_streambuf() );
internal::dealloc_streambuf( buf );
}
=== removed file 'include/zorba/file.h'
--- include/zorba/file.h 2013-04-19 22:25:21 +0000
+++ include/zorba/file.h 1970-01-01 00:00:00 +0000
@@ -1,100 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef ZORBA_FILE_API_H
-#define ZORBA_FILE_API_H
-
-#include <string>
-
-#include <zorba/config.h>
-#include <zorba/api_shared_types.h>
-
-namespace zorba {
-
- /** \brief This class is the representation of file system file.
- *
- * ...
- */
- class ZORBA_DLL_PUBLIC DirectoryIterator : public SmartObject
- {
- public:
-
- virtual ~DirectoryIterator() {}
-
- virtual bool next(std::string& aPathStr) const = 0;
- /** \brief Rewind the file find iterator
- */
- virtual void reset() = 0;
- };
-
-
- /** \brief This class is the representation of file system file.
- *
- * ...
- */
- class ZORBA_DLL_PUBLIC File : public SmartObject
- {
- public: // constructors
-
- virtual ~File() {}
-
- static File_t createFile(const std::string& path);
-
- static const char* getDirectorySeparator();
-
- static const char* getPathSeparator();
-
- public: // type, enums
-
-#ifdef WIN32
- typedef __int64 FileSize_t;
-#else
- typedef int64_t FileSize_t;
-#endif
-
-
- public: // public methods
-
- virtual const std::string getFilePath() const = 0;
- virtual const std::string getFileUri() const = 0;
-
- virtual bool isDirectory( bool follow_symlinks = true ) const = 0;
- virtual bool isFile( bool follow_symlinks = true ) const = 0;
- virtual bool isLink() const = 0;
- virtual bool isVolume( bool follow_symlinks = true ) const = 0;
- virtual bool isInvalid() const = 0; // deprecated
- virtual bool exists( bool follow_symlinks = true ) const = 0;
-
- virtual void remove() = 0;
- virtual bool create() = 0;
- virtual bool rename(std::string const& newpath) = 0;
-
- virtual FileSize_t getSize() const = 0;
-
- virtual void mkdir(bool recursive) = 0;
-
- virtual DirectoryIterator_t files() const = 0;
-
- virtual void openInputStream(std::ifstream& aInStream, bool binary, bool trimByteOrderMark) const = 0;
- virtual void openOutputStream(std::ofstream& aOutStream, bool binary, bool append) const = 0;
-
- virtual time_t lastModified() const = 0;
-
- };
-
-} /* namespace zorba */
-
-#endif
-/* vim:set et sw=2 ts=2: */
=== renamed file 'src/util/cxx_util.h' => 'include/zorba/internal/cxx_util.h'
--- src/util/cxx_util.h 2013-02-07 17:24:36 +0000
+++ include/zorba/internal/cxx_util.h 2013-06-03 23:16:28 +0000
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ZORBA_CXX_UTIL_H
-#define ZORBA_CXX_UTIL_H
+#ifndef ZORBA_INTERNAL_CXX_UTIL_H
+#define ZORBA_INTERNAL_CXX_UTIL_H
#include <zorba/config.h>
@@ -24,6 +24,7 @@
#ifndef ZORBA_CXX_NULLPTR
namespace zorba {
+namespace internal {
/**
* A \c nullptr type.
@@ -45,6 +46,7 @@
void operator&() const; // whose address can't be taken
};
+} // namespace internal
} // namespace zorba
/**
@@ -55,7 +57,7 @@
* Bjarne's paper has a slight performance penalty.
*/
ZORBA_DLL_PUBLIC
-extern zorba::nullptr_type const zorba_nullptr;
+extern zorba::internal::nullptr_type const zorba_nullptr;
#define nullptr ::zorba_nullptr
@@ -78,5 +80,5 @@
///////////////////////////////////////////////////////////////////////////////
-#endif /* ZORBA_CXX_UTIL_H */
+#endif /* ZORBA_INTERNAL_CXX_UTIL_H */
/* vim:set et sw=2 ts=2: */
=== modified file 'include/zorba/internal/unique_ptr.h'
--- include/zorba/internal/unique_ptr.h 2013-02-07 17:24:36 +0000
+++ include/zorba/internal/unique_ptr.h 2013-06-03 23:16:28 +0000
@@ -25,6 +25,7 @@
#else
#include <algorithm> /* for swap() */
+#include "cxx_util.h"
#include "type_traits.h"
#include "ztd.h"
@@ -159,7 +160,8 @@
*/
template<typename U>
default_delete( default_delete<U> const&,
- typename enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type* = 0 )
+ typename enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type*
+ = nullptr )
{
}
@@ -218,7 +220,7 @@
*
* @param p A pointer to the object to point to, if any.
*/
- explicit unique_ptr( pointer p = 0 ) throw() : storage_( p ) {
+ explicit unique_ptr( pointer p = nullptr ) throw() : storage_( p ) {
}
/**
@@ -266,7 +268,7 @@
!ZORBA_TR1_NS::is_reference<D>::value ||
ZORBA_TR1_NS::is_same<D,E>::value
)
- >::type* = 0
+ >::type* = nullptr
) :
storage_( p.release(), move<D>( p.get_deleter() ) )
{
@@ -374,7 +376,7 @@
*/
pointer release() throw() {
pointer const temp = get();
- storage_.ptr_ = 0;
+ storage_.ptr_ = nullptr;
return temp;
}
@@ -385,7 +387,7 @@
*
* @param p The new pointer value, if any.
*/
- void reset( pointer p = 0 ) throw() {
+ void reset( pointer p = nullptr ) throw() {
if ( p != storage_.ptr_ ) {
call_deleter();
storage_.ptr_ = p;
@@ -462,7 +464,7 @@
typedef T* pointer;
typedef D deleter_type;
- explicit unique_ptr( pointer p = 0 ) throw() : storage_( p ) {
+ explicit unique_ptr( pointer p = nullptr ) throw() : storage_( p ) {
}
unique_ptr( pointer p, deleter_reference d ) : storage_( p, d ) {
@@ -496,11 +498,11 @@
pointer release() throw() {
pointer const temp = get();
- storage_.ptr_ = 0;
+ storage_.ptr_ = nullptr;
return temp;
}
- void reset( pointer p = 0 ) throw() {
+ void reset( pointer p = nullptr ) throw() {
if ( p != storage_.ptr_ ) {
call_deleter();
storage_.ptr_ = p;
=== modified file 'include/zorba/internal/ztd.h'
--- include/zorba/internal/ztd.h 2013-05-09 00:48:27 +0000
+++ include/zorba/internal/ztd.h 2013-06-03 23:16:28 +0000
@@ -24,6 +24,7 @@
#include <zorba/config.h>
+#include "cxx_util.h"
#include "type_traits.h"
///////////////////////////////////////////////////////////////////////////////
@@ -210,7 +211,8 @@
template<typename U>
destroy_delete( destroy_delete<U> const&,
typename
- std::enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type* = 0 )
+ std::enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type*
+ = nullptr )
{
}
=== modified file 'include/zorba/stemmer.h'
--- include/zorba/stemmer.h 2013-02-07 17:24:36 +0000
+++ include/zorba/stemmer.h 2013-06-03 23:16:28 +0000
@@ -21,6 +21,7 @@
#ifndef ZORBA_NO_FULL_TEXT
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/unique_ptr.h>
#include <zorba/internal/ztd.h>
#include <zorba/locale.h>
@@ -98,7 +99,7 @@
* \a lang.
*/
virtual bool getStemmer( locale::iso639_1::type lang,
- Stemmer::ptr *s = 0 ) const = 0;
+ Stemmer::ptr *s = nullptr ) const = 0;
};
///////////////////////////////////////////////////////////////////////////////
=== modified file 'include/zorba/thesaurus.h'
--- include/zorba/thesaurus.h 2013-02-07 17:24:36 +0000
+++ include/zorba/thesaurus.h 2013-06-03 23:16:28 +0000
@@ -21,6 +21,7 @@
#ifndef ZORBA_NO_FULL_TEXT
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/unique_ptr.h>
#include <zorba/internal/ztd.h>
#include <zorba/locale.h>
@@ -128,7 +129,7 @@
* \a lang.
*/
virtual bool getThesaurus( locale::iso639_1::type lang,
- Thesaurus::ptr *t = 0 ) const = 0;
+ Thesaurus::ptr *t = nullptr ) const = 0;
};
///////////////////////////////////////////////////////////////////////////////
=== modified file 'include/zorba/tokenizer.h'
--- include/zorba/tokenizer.h 2013-02-07 17:24:36 +0000
+++ include/zorba/tokenizer.h 2013-06-03 23:16:28 +0000
@@ -21,9 +21,10 @@
#include <vector>
#include <zorba/config.h>
-#include <zorba/locale.h>
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/unique_ptr.h>
#include <zorba/internal/ztd.h>
+#include <zorba/locale.h>
namespace zorba {
@@ -101,7 +102,7 @@
virtual void token( char const *utf8_s, size_type utf8_len,
locale::iso639_1::type lang,
size_type token_no, size_type sent_no,
- size_type para_no, Item const *item = 0 ) = 0;
+ size_type para_no, Item const *item = nullptr ) = 0;
};
/////////////////////////////////////////////////////////////////////////////
@@ -200,7 +201,8 @@
*/
virtual void tokenize_string( char const *utf8_s, size_type utf8_len,
locale::iso639_1::type lang, bool wildcards,
- Callback &callback, Item const *item = 0 ) = 0;
+ Callback &callback,
+ Item const *item = nullptr ) = 0;
/////////////////////////////////////////////////////////////////////////////
@@ -295,8 +297,8 @@
* \a lang.
*/
virtual bool getTokenizer( locale::iso639_1::type lang,
- Tokenizer::State *state = 0,
- Tokenizer::ptr *t = 0 ) const = 0;
+ Tokenizer::State *state = nullptr,
+ Tokenizer::ptr *t = nullptr ) const = 0;
};
///////////////////////////////////////////////////////////////////////////////
=== modified file 'include/zorba/transcode_stream.h'
--- include/zorba/transcode_stream.h 2013-02-26 04:12:43 +0000
+++ include/zorba/transcode_stream.h 2013-06-03 23:16:28 +0000
@@ -18,6 +18,7 @@
#define ZORBA_TRANSCODE_STREAM_API_H
#include <zorba/config.h>
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/streambuf.h>
#include <zorba/internal/unique_ptr.h>
@@ -164,7 +165,7 @@
void detach( std::basic_ios<charT,Traits> &ios ) {
int const index = internal::transcode::get_streambuf_index();
if ( streambuf *const buf = static_cast<streambuf*>( ios.pword( index ) ) ) {
- ios.pword( index ) = 0;
+ ios.pword( index ) = nullptr;
ios.rdbuf( buf->orig_streambuf() );
internal::dealloc_streambuf( buf );
}
=== modified file 'include/zorba/user_exception.h'
--- include/zorba/user_exception.h 2013-02-07 17:24:36 +0000
+++ include/zorba/user_exception.h 2013-06-03 23:16:28 +0000
@@ -21,6 +21,7 @@
#include <zorba/api_shared_types.h>
#include <zorba/error.h>
+#include <zorba/internal/cxx_util.h>
#include <zorba/xquery_exception.h>
namespace zorba {
@@ -60,7 +61,7 @@
ZorbaException::line_type raise_line,
char const *ns, char const *prefix, char const *localname,
char const *description, diagnostic::location const &loc,
- error_object_type *error_object = 0 );
+ error_object_type *error_object = nullptr );
/**
* \internal
@@ -83,7 +84,7 @@
ZorbaException::line_type raise_line,
Error const &error, char const *description,
diagnostic::location const &loc,
- error_object_type *error_object = 0 );
+ error_object_type *error_object = nullptr );
} // namespace internal
@@ -369,7 +370,7 @@
make_user_exception( char const *raise_file,
ZorbaException::line_type raise_line,
Error const &error, String const &description,
- error_object_type *error_object = 0 );
+ error_object_type *error_object = nullptr );
///////////////////////////////////////////////////////////////////////////////
=== renamed file 'src/util/error_util.h' => 'include/zorba/util/error_util.h'
--- src/util/error_util.h 2013-05-08 01:05:04 +0000
+++ include/zorba/util/error_util.h 2013-06-03 23:16:28 +0000
@@ -15,10 +15,13 @@
*/
#pragma once
-#ifndef ZORBA_ERROR_UTIL_H
-#define ZORBA_ERROR_UTIL_H
+#ifndef ZORBA_API_ERROR_UTIL_H
+#define ZORBA_API_ERROR_UTIL_H
#include <zorba/config.h>
+#include <zorba/internal/cxx_util.h>
+#include <zorba/internal/type_traits.h>
+#include <zorba/internal/ztd.h>
#include <stdexcept>
#ifndef WIN32
@@ -27,9 +30,6 @@
# include <windows.h>
#endif /* WIN32 */
-#include "cxx_util.h"
-#include "string_util.h"
-
namespace zorba {
namespace os_error {
@@ -47,7 +47,7 @@
* An %exception is-a std::runtime_error for reporting errors with operating
* system or library functions.
*/
-class exception : public std::runtime_error {
+class ZORBA_DLL_PUBLIC exception : public std::runtime_error {
public:
/**
* Constructs an %exception.
@@ -60,11 +60,7 @@
* the operating system error string; if empty, no error string is used.
*/
exception( char const *function, char const *path,
- char const *err_string = nullptr ) :
- std::runtime_error( make_what( function, path, err_string ) ),
- function_( function ), path_( path )
- {
- }
+ char const *err_string = nullptr );
/**
* Destroys an %exception.
@@ -90,9 +86,6 @@
}
protected:
- static std::string make_what( char const *function, char const *path,
- char const *err_string = nullptr );
-
std::string function_;
std::string path_;
};
@@ -106,6 +99,7 @@
* @param err_string The error string.
* @return Returns said error string.
*/
+ZORBA_DLL_PUBLIC
std::string format_err_string( char const *function, char const *err_string );
/**
@@ -116,6 +110,7 @@
* @param err_string The error string.
* @return Returns said error string.
*/
+ZORBA_DLL_PUBLIC
std::string format_err_string( char const *function, code_type code,
char const *err_string );
@@ -139,6 +134,7 @@
* @param code The operating system error code.
* @return Returns said error string.
*/
+ZORBA_DLL_PUBLIC
std::string get_err_string( char const *function,
code_type code = get_err_code() );
@@ -170,8 +166,7 @@
} // namespace os_error
} // namespace zorba
-
-#endif /* ZORBA_ERROR_UTIL_H */
+#endif /* ZORBA_API_ERROR_UTIL_H */
/*
* Local variables:
* mode: c++
=== removed file 'include/zorba/util/file.h'
--- include/zorba/util/file.h 2013-04-19 22:25:21 +0000
+++ include/zorba/util/file.h 1970-01-01 00:00:00 +0000
@@ -1,122 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ZORBA_FILE_H
-#define ZORBA_FILE_H
-
-#ifndef WIN32
-#include <stdint.h>
-#endif
-
-#include <cstdio>
-#include <string>
-#include <time.h>
-#include <vector>
-
-#include <zorba/config.h>
-#include <zorba/file.h>
-#include <zorba/util/path.h>
-
-namespace zorba {
-
-class ZORBA_DLL_PUBLIC file : public filesystem_path
-{
-public:
-
- enum filetype {
- type_invalid,
- type_non_existent,
- type_directory,
- type_link,
- type_file,
- type_volume,
- type_other
- };
-
- typedef zorba::File::FileSize_t file_size_t;
-
-protected:
- filetype do_stat( bool follow_symlinks = true, file_size_t *size = 0 ) const;
-
-public:
- file(const filesystem_path &path, int flags = 0);
-
-public: // common methods
- void set_path(std::string const& _path ) { *((filesystem_path *) this) = _path; }
- void set_filetype(filetype) { /* do nothing */ } // deprecated
-
- filetype get_filetype( bool follow_symlinks = true ) const {
- return do_stat( follow_symlinks );
- }
-
- bool is_directory( bool follow_symlinks = true ) const {
- return do_stat( follow_symlinks ) == type_directory;
- }
-
- bool is_file( bool follow_symlinks = true ) const {
- return do_stat( follow_symlinks ) == type_file;
- }
-
- bool is_link() const {
- return do_stat( false ) == type_link;
- }
-
- bool is_volume( bool follow_symlinks = true ) const {
- return do_stat( follow_symlinks ) == type_volume;
- }
-
- bool is_invalid() const { // deprecated
- return false;
- }
-
- bool exists( bool follow_symlinks = true ) const {
- return do_stat( follow_symlinks ) != type_non_existent;
- }
-
- time_t lastModified() const;
-
-public: // file methods
- void create();
- void remove(bool ignore = true);
- void rename(std::string const& newpath);
-
- file_size_t get_size() const {
- file_size_t size;
- do_stat( true, &size );
- return size;
- }
-
-public: // directory methods
- void mkdir();
- void deep_mkdir();
- void rmdir(bool ignore = true);
- void lsdir(std::vector<std::string> &list);
-#ifndef _WIN32_WCE
- void chdir();
-#endif
-
- bool is_empty() const { return get_size() == 0; }
-};
-
-
-} // namespace zorba
-#endif /* ZORBA_FILE_H */
-/*
- * Local variables:
- * mode: c++
- * End:
- */
-/* vim:set et sw=2 ts=2: */
=== added file 'include/zorba/util/fs_util.h'
--- include/zorba/util/fs_util.h 1970-01-01 00:00:00 +0000
+++ include/zorba/util/fs_util.h 2013-06-03 23:16:28 +0000
@@ -0,0 +1,622 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ZORBA_API_FS_UTIL_H
+#define ZORBA_API_FS_UTIL_H
+
+// standard
+#include <cctype>
+#include <iostream>
+#include <string>
+#ifdef WIN32
+# include <windows.h>
+#else
+# include <dirent.h>
+# include <sys/types.h> /* for off_t */
+#endif /* WIN32 */
+
+#ifndef MAX_PATH
+/**
+ * Maximum path length. This is defined under Windows to be 1024. There is no
+ * equivalent constant/macro for *nix systems, so simply borrow Windows' value.
+ */
+#define MAX_PATH 1024
+#endif /* MAX_PATH */
+
+// Zorba
+#include <zorba/config.h>
+#include <zorba/internal/cxx_util.h>
+#include <zorba/internal/ztd.h>
+#include <zorba/util/error_util.h>
+
+namespace zorba {
+namespace fs {
+
+////////// Exceptions /////////////////////////////////////////////////////////
+
+typedef os_error::exception exception;
+
+////////// constants //////////////////////////////////////////////////////////
+
+#ifdef WIN32
+char const dir_separator = '\\';
+char const path_separator = ';';
+#else
+char const dir_separator = '/';
+char const path_separator = ':';
+#endif /* WIN32 */
+
+////////// types //////////////////////////////////////////////////////////////
+
+/**
+ * File size type.
+ */
+#ifdef WIN32
+typedef __int64 size_type;
+#else
+typedef off_t size_type;
+#endif /* WIN32 */
+
+/**
+ * File type.
+ */
+enum type {
+ non_existent,
+ directory,
+ file,
+ link,
+ volume,
+ other // named pipe, character/block special, socket, etc.
+};
+extern char const *const type_string[];
+
+/**
+ * Emits the string representation of a file type to the given ostream.
+ *
+ * @param o The ostream to emit to.
+ * @param t The file type to emit.
+ * @return Returns \a o.
+ */
+inline std::ostream& operator<<( std::ostream &o, type t ) {
+ return o << type_string[ t ];
+}
+
+////////// Windows ////////////////////////////////////////////////////////////
+
+#ifdef WIN32
+namespace win32 {
+
+// Do not use this function directly.
+ZORBA_DLL_PUBLIC
+void make_absolute_impl( char const *path, char *abs_path );
+
+} // namespace win32
+#endif /* WIN32 */
+
+////////// Directory //////////////////////////////////////////////////////////
+
+/**
+ * Gets the current directory.
+ *
+ * @return Returns said directory.
+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR if it
+ * fails.
+ */
+ZORBA_DLL_PUBLIC
+std::string curdir();
+
+#ifdef ZORBA_WITH_FILE_ACCESS
+
+/**
+ * Creates a directory.
+ *
+ * @param path The full path of the directory to create.
+ * @throws fs::exception if the creation fails.
+ */
+ZORBA_DLL_PUBLIC
+void mkdir( char const *path );
+
+/**
+ * Creates a directory.
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The full path of the directory to create.
+ * @throws fs::exception if the creation fails.
+ */
+template<class PathStringType> inline
+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),void>::type
+mkdir( PathStringType const &path ) {
+ mkdir( path.c_str() );
+}
+
+#endif /* ZORBA_WITH_FILE_ACCESS */
+
+////////// File deletion //////////////////////////////////////////////////////
+
+#ifdef ZORBA_WITH_FILE_ACCESS
+
+/**
+ * Removes the given file or directory.
+ *
+ * @param path The full path of the file or directory to remove.
+ * @param ignore_not_found If \c true, a non-existant \a path will not throw an
+ * exception.
+ * @return Returns \c true if removal succeeds and \c false if it fails and
+ * \a ignore_not_found is \c true.
+ * @throws fs::exception if the removal fails unless \a path is non-existant
+ * and \a ignore_not_found is \c true.
+ */
+ZORBA_DLL_PUBLIC
+bool remove( char const *path, bool ignore_not_found = false );
+
+/**
+ * Removes the given file or directory.
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The full path of the file or directory to remove.
+ * @param ignore_not_found If \c true, a non-existant \a path will not throw an
+ * exception.
+ * @return Returns \c true if removal succeeds and \c false if it fails and
+ * \a ignore_not_found is \c true.
+ * @throws fs::exception if the removal fails unless \a path is non-existant
+ * and \a ignore_not_found is \c true.
+ */
+template<class PathStringType> inline
+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),bool>::type
+remove( PathStringType const &path, bool ignore_not_found = false ) {
+ return remove( path.c_str(), ignore_not_found );
+}
+
+#endif /* ZORBA_WITH_FILE_ACCESS */
+
+////////// File information ///////////////////////////////////////////////////
+
+/**
+ * Checks whether the given path is an absolute path.
+ *
+ * @param path The full path to check.
+ * @return Returns \c true only if the path is absolute.
+ */
+inline bool is_absolute( char const *path ) {
+#ifndef WIN32
+ return path[0] == '/';
+#else
+ //
+ // No, this should NOT also check for '/'. The path should have been
+ // normalized for Windows first, i.e., have '/' replaced by '\'.
+ //
+ return isalpha( path[0] ) && path[1] == ':' && path[2] == '\\';
+#endif /* WIN32 */
+}
+
+/**
+ * Checks whether the given path is an absolute path.
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The full path to check.
+ * @return Returns \c true only if the path is absolute.
+ */
+template<class PathStringType> inline
+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),bool>::type
+is_absolute( PathStringType const &path ) {
+ return is_absolute( path.c_str() );
+}
+
+/**
+ * Gets the base name of the given path name, i.e., the file name without the
+ * path leading up to it.
+ *
+ * @param path The full path to get the base name of.
+ * @return Returns the base name. Note that if \a path is just a file name,
+ * then returns \a path.
+ */
+inline char const* base_name( char const *path ) {
+ char const *const sep = ::strrchr( path, dir_separator );
+ return sep && sep[1] ? sep + 1 : path;
+}
+
+/**
+ * Gets the base name of the given path name, i.e., the file name without the
+ * path leading up to it.
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The full path to get the base name of.
+ * @return Returns the base name. If \a path is just a file name, returns
+ * \a path.
+ */
+template<class PathStringType> inline
+typename std::enable_if<ZORBA_IS_STRING(PathStringType),PathStringType>::type
+base_name( PathStringType const &path ) {
+ typename PathStringType::size_type const pos = path.rfind( dir_separator );
+ return pos != PathStringType::npos && pos < path.size() - 1 ?
+ path.substr( pos + 1 ) : path;
+}
+
+/**
+ * Gets the directory name of the given path name, i.e., the path up to but not
+ * including the last path component.
+ *
+ * @param path The path to get the directory name of.
+ * @return Returns the direcory path. If \a path is just a file name, returns
+ * <code>'.'</code>.
+ */
+inline std::string dir_name( char const *path ) {
+ if ( char const *const sep = ::strrchr( path, dir_separator ) )
+ return sep == path ?
+ std::string( 1, dir_separator ) : std::string( path, sep );
+ return std::string( 1, '.' );
+}
+
+/**
+ * Gets the directory name of the given path name, i.e., the path up to but not
+ * including the last path component.
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The path to get the directory name of.
+ * @return Returns the direcory path. If \a path is just a file name, returns
+ * <code>'.'</code>.
+ */
+template<class PathStringType> inline
+typename std::enable_if<ZORBA_IS_STRING(PathStringType),PathStringType>::type
+dir_name( PathStringType const &path ) {
+ typename PathStringType::size_type const pos = path.rfind( dir_separator );
+ if ( pos == PathStringType::npos )
+ return PathStringType( 1, '.' );
+ if ( pos == 0 ) // e.g., /foo
+ return PathStringType( 1, dir_separator );
+#ifdef WIN32
+ if ( pos == 2 && is_absolute( path ) )
+ return path.substr( 0, 3 );
+#endif /* WIN32 */
+ return path.substr( 0, pos );
+}
+
+#ifdef ZORBA_WITH_FILE_ACCESS
+
+/**
+ * File information for use with get_type().
+ */
+struct info {
+ time_t mtime; ///< file's last modification time (in seconds since epoch)
+ size_type size; ///< file's size in bytes
+ fs::type type; ///< file's type
+};
+
+/**
+ * Gets the type of the given file.
+ *
+ * @param path The full path to check.
+ * @param follow_symlink If \c true, follows symbolic links.
+ * @param pinfo A pointer to a receive file information, or \c null.
+ * @return If \a path refers to a symbolic link and \a follow_symlink is
+ * \c true, the type returned is of that to which the link refers; if \a path
+ * refers to a symbolic and \a follow_symlink is \c false, returns \c link; if
+ * \a path does not refer to a symbolic link, returns the type of \a path.
+ * @throws fs::exception for typical failures (file not found, invalid path,
+ * permission denied, etc).
+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
+ * unrecoverable failures.
+ */
+ZORBA_DLL_PUBLIC
+type get_type( char const *path, bool follow_symlink, info *pinfo = nullptr );
+
+/**
+ * Gets the type of the given file.
+ *
+ * @param path The full path to check.
+ * @param pinfo A pointer to a receive file information, or \c null.
+ * @return If \a path refers to a symbolic link, the type returned is of that
+ * to which the link refers; if \a path does not refer to a symbolic link,
+ * returns the type of \a path.
+ * @throws fs::exception for typical failures (file not found, invalid path,
+ * permission denied, etc).
+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
+ * unrecoverable failures.
+ */
+inline type get_type( char const *path, info *pinfo = nullptr ) {
+ return get_type( path, true, pinfo );
+}
+
+/**
+ * Gets the type of the given file.
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The full path to check.
+ * @param follow_symlink If \c true, follows symbolic links.
+ * @param pinfo A pointer to a receive file information, or \c null.
+ * @return If \a path refers to a symbolic link and \a follow_symlink is
+ * \c true, the type returned is of that to which the link refers; if \a path
+ * refers to a symbolic and \a follow_symlink is \c false, returns \c link; if
+ * \a path does not refer to a symbolic link, returns the type of \a path.
+ * @throws fs::exception for typical failures (file not found, invalid path,
+ * permission denied, etc).
+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
+ * unrecoverable failures.
+ */
+template<class PathStringType> inline
+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),type>::type
+get_type( PathStringType const &path, bool follow_symlink,
+ info *pinfo = nullptr ) {
+ return get_type( path.c_str(), follow_symlink, pinfo );
+}
+
+/**
+ * Gets the type of the given file.
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The full path to check.
+ * @param pinfo A pointer to a receive file information, or \c null.
+ * @return If \a path refers to a symbolic link, the type returned is of that
+ * to which the link refers; if \a path does not refer to a symbolic link,
+ * returns the type of \a path.
+ * @throws fs::exception for typical failures (file not found, invalid path,
+ * permission denied, etc).
+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
+ * unrecoverable failures.
+ */
+template<class PathStringType> inline
+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),type>::type
+get_type( PathStringType const &path, info *pinfo = nullptr ) {
+ return get_type( path.c_str(), pinfo );
+}
+
+#endif /* ZORBA_WITH_FILE_ACCESS */
+
+////////// Directory iteration ////////////////////////////////////////////////
+
+#ifdef ZORBA_WITH_FILE_ACCESS
+
+/**
+ * An %fs::iterator iterates over the entries in a directory.
+ */
+class ZORBA_DLL_PUBLIC iterator {
+public:
+ /**
+ * Constructs an %iterator.
+ *
+ * @param path The full path to the directory to iterate over.
+ * @throws fs::exception if the construction failed, e.g., path not found.
+ */
+ iterator( char const *path ) : dir_path_( path ) {
+ ctor_impl();
+ }
+
+ /**
+ * Constructs an %iterator.
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The full path to the directory to iterate over.
+ * @throws fs::exception if the construction failed, e.g., path not found.
+ */
+ template<class PathStringType>
+ iterator( PathStringType const &path,
+ typename std::enable_if<ZORBA_HAS_C_STR(PathStringType)
+ >::type* = 0 ) : dir_path_( path.c_str() ) {
+ ctor_impl();
+ }
+
+ /**
+ * Destroys this %iterator.
+ */
+ ~iterator();
+
+ /**
+ * Attempts to get the next directory entry.
+ *
+ * @return Returns \c true only if there is a next directory.
+ */
+ bool next();
+
+ /**
+ * Gets the name of the curent directory entry.
+ *
+ * @return Returns said name.
+ */
+ char const* entry_name() const {
+# ifndef WIN32
+ return ent_->d_name;
+# else
+ return ent_name_;
+# endif /* WIN32 */
+ }
+
+ /**
+ * Gets the type of the current directory entry.
+ *
+ * @return Returns said type.
+ */
+ type entry_type() const {
+ return ent_type_;
+ }
+
+ /**
+ * Gets the directory's path.
+ *
+ * @return Returns said path.
+ */
+ char const* path() const {
+ return dir_path_.c_str();
+ }
+
+ /**
+ * Resets this iterator to the beginning.
+ */
+ void reset();
+
+private:
+ std::string dir_path_;
+ type ent_type_;
+#ifndef WIN32
+ DIR *dir_;
+ struct dirent *ent_;
+#else
+ HANDLE dir_;
+ bool dir_is_empty_;
+ WIN32_FIND_DATA ent_data_;
+ char ent_name_[ MAX_PATH ];
+ bool use_first_;
+
+ void win32_opendir( char const *path );
+ void win32_closedir();
+#endif /* WIN32 */
+
+ void ctor_impl();
+
+ // forbid
+ iterator( iterator const& );
+ iterator& operator=( iterator const& );
+};
+
+#endif /* ZORBA_WITH_FILE_ACCESS */
+
+////////// Path normalization /////////////////////////////////////////////////
+
+/**
+ * Gets the normalized path of the given path. A normalized path is one that:
+ * - has \c file:// URIs converted to paths
+ * - has directory separators corrected for the host operating system
+ * - has adjacent directory separators combined, e.g., \c /a//b becomes \c /a/b
+ * - has \c ./ removed, e.g., \c /a/./b becomes \c /a/b
+ * - has \c ../ removed, e.g., \c /a/b/../c becomes \c /a/c
+ *
+ * @param path The path to normalize.
+ * @param base The base path. If not empty, is prepended to \a path.
+ * @return Returns the normalized path.
+ * @throws std::invalid_argument for malformed paths.
+ */
+ZORBA_DLL_PUBLIC
+std::string normalize_path( char const *path, char const *base = nullptr );
+
+/**
+ * Gets the normalized path of the given path. A normalized path is one that:
+ * - has \c file:// URIs converted to paths
+ * - has directory separators corrected for the host operating system
+ * - has adjacent directory separators combined, e.g., \c /a//b becomes \c /a/b
+ * - has \c ./ removed, e.g., \c /a/./b becomes \c /a/b
+ * - has \c ../ removed, e.g., \c /a/b/../c becomes \c /a/c
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The path to normalize.
+ * @return Returns the normalized path.
+ * @throws std::invalid_argument for malformed paths.
+ */
+template<class PathStringType> inline
+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),std::string>::type
+normalize_path( PathStringType const &path ) {
+ return normalize_path( path.c_str() );
+}
+
+/**
+ * Gets the normalized path of the given path. A normalized path is one that:
+ * - has \c file:// URIs converted to paths
+ * - has directory separators corrected for the host operating system
+ * - has adjacent directory separators combined, e.g., \c /a//b becomes \c /a/b
+ * - has \c ./ removed, e.g., \c /a/./b becomes \c /a/b
+ * - has \c ../ removed, e.g., \c /a/b/../c becomes \c /a/c
+ *
+ * @tparam PathStringType The \a path string type.
+ * @tparam BaseStringType The \a base string type.
+ * @param path The path to normalize.
+ * @param base The base path. If not empty, is prepended to \a path.
+ * @return Returns the normalized path.
+ * @throws std::invalid_argument for malformed paths.
+ */
+template<class PathStringType,class BaseStringType> inline
+typename std::enable_if<ZORBA_HAS_C_STR(PathStringType)
+ && ZORBA_HAS_C_STR(BaseStringType),
+ std::string>::type
+normalize_path( PathStringType const &path, BaseStringType const &base ) {
+ return normalize_path( path.c_str(), base.c_str() );
+}
+
+////////// Path manipulation //////////////////////////////////////////////////
+
+/**
+ * Appends a path component onto another path ensuring that exactly one
+ * separator is used.
+ *
+ * @tparam PathStringType1 The \a path1 string type.
+ * @param path1 The path to append to.
+ * @param path2 The path to append.
+ */
+template<class PathStringType1> inline
+typename std::enable_if<ZORBA_IS_STRING(PathStringType1),void>::type
+append( PathStringType1 &path1, char const *path2 ) {
+ if ( !path1.empty() && path1[ path1.size() - 1 ] != dir_separator
+ && path2[0] != dir_separator ) {
+ path1 += dir_separator;
+ }
+ path1 += path2;
+}
+
+/**
+ * Appends a path component onto another path.
+ *
+ * @tparam PathStringType1 The \a path1 string type.
+ * @tparam PathStringType2 The \a path2 string type.
+ * @param path1 The path to append to.
+ * @param path2 The path to append.
+ */
+template<class PathStringType1,class PathStringType2> inline
+typename std::enable_if<ZORBA_IS_STRING(PathStringType1)
+ && ZORBA_HAS_C_STR(PathStringType2),
+ void>::type
+append( PathStringType1 &path1, PathStringType2 const &path2 ) {
+ append( path1, path2.c_str() );
+}
+
+/**
+ * Makes a relative path into an absolute path.
+ *
+ * @param path The path to make absolute. It is assumes that the buffer to
+ * which \a path points is at least MAX_PATH bytes.
+ */
+ZORBA_DLL_PUBLIC
+void make_absolute( char *path );
+
+/**
+ * Makes a relative path into an absolute path.
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The path to make absolute.
+ */
+template<class PathStringType> inline
+typename std::enable_if<ZORBA_IS_STRING(PathStringType),void>::type
+make_absolute( PathStringType &path ) {
+ if ( !is_absolute( path ) ) {
+#ifndef WIN32
+ typedef typename PathStringType::size_type size_type;
+ path.insert( static_cast<size_type>(0), 1, '/' );
+ path.insert( 0, curdir().c_str() );
+#else
+ char temp[ MAX_PATH ];
+ win32::make_absolute_impl( path.c_str(), temp );
+ path = temp;
+#endif /* WIN32 */
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+} // namespace fs
+} // namespace zorba
+#endif /* ZORBA_API_FS_UTIL_H */
+/*
+* Local variables:
+* mode: c++
+* End:
+*/
+/* vim:set et sw=2 ts=2: */
=== removed file 'include/zorba/util/path.h'
--- include/zorba/util/path.h 2013-02-07 17:24:36 +0000
+++ include/zorba/util/path.h 1970-01-01 00:00:00 +0000
@@ -1,105 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ZORBA_PATH_H
-#define ZORBA_PATH_H
-
-#include <string>
-#include <iostream>
-#include <zorba/config.h>
-
-namespace zorba {
-
-class ZORBA_DLL_PUBLIC filesystem_path {
-private:
- std::string path;
-
- void canonicalize ();
-
-protected:
- std::string
- getPathString() const;
-
-public:
- enum flags_t {
- CONVERT_SLASHES = 1,
- RESOLVE = 2
- };
-
-public:
-
- /**
- * @brief Utility function to normalize a path as a system conforming
- * path and optionally resolve it.
- *
- * This function takes a path (as system path, file uri) and normalizes it.
- * It converts file URIs to system paths and replaces '/' and '\' to the
- * platform specific directory separator ('\' on Windows, '/' on UNIX like
- * operating systems like Linux and Mac OS X).
- * If the parameter base is set, it also resolves the path.
- *
- * @param in The path to normalize.
- * @param base The base name to resolve a path (default = ""), if this is the
- * empty string, it does not resolve anything, but only normalizes
- * the path.
- * @return Returns a normalized and optionally a resolved path.
- */
- static std::string normalize_path(std::string const &in, std::string const &base = "");
-
- // from current dir
- filesystem_path ();
-
- filesystem_path (const std::string &path_, int flags = 0);
-
- filesystem_path (const filesystem_path &base, const filesystem_path &rel) {
- if (rel.is_complete ())
- *this = rel;
- else {
- *this = base.get_path () + get_directory_separator () + rel.get_path ();
- canonicalize ();
- }
- }
-
- filesystem_path &operator = (const std::string &p_)
- { path = p_; canonicalize (); return *this; }
-
- const std::string &get_path () const { return path; }
- const char *c_str () const { return path.c_str (); }
- operator const std::string & () const { return path; }
-
- bool is_complete () const;
- bool is_root () const;
- void resolve_relative ();
-
- filesystem_path branch_path () const;
-
- static const char *get_directory_separator ();
- static const char *get_path_separator ();
-};
-
-inline std::ostream &operator<< (std::ostream &os, const filesystem_path &p) {
- return os << p.get_path ();
-}
-
-
-} // namespace zorba
-#endif /* ZORBA_PATH_H */
-/*
-* Local variables:
-* mode: c++
-* End:
-*/
-/* vim:set et sw=2 ts=2: */
=== added file 'include/zorba/util/stream_util.h'
--- include/zorba/util/stream_util.h 1970-01-01 00:00:00 +0000
+++ include/zorba/util/stream_util.h 2013-06-03 23:16:28 +0000
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#ifndef ZORBA_API_STREAM_UTIL_H
+#define ZORBA_API_STREAM_UTIL_H
+
+#include <iostream>
+
+namespace zorba {
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Skips the UTF-8 byte order mark (BOM), if any.
+ *
+ * @param is The istream to read.
+ * @return Returns \c true only if a BOM was present and skipped.
+ */
+bool skip_utf8_bom( std::istream &is );
+
+///////////////////////////////////////////////////////////////////////////////
+
+} // namespace zorba
+
+#endif /* ZORBA_API_STREAM_UTIL_H */
+/*
+ * Local variables:
+ * mode: c++
+ * End:
+ */
+/* vim:set et sw=2 ts=2: */
=== modified file 'modules/org/expath/ns/file.xq.src/file.cpp'
--- modules/org/expath/ns/file.xq.src/file.cpp 2013-04-19 22:25:21 +0000
+++ modules/org/expath/ns/file.xq.src/file.cpp 2013-06-03 23:16:28 +0000
@@ -16,25 +16,28 @@
#include "file.h"
+// standard
#include <fstream>
#include <memory>
#include <sstream>
#include <stdexcept>
+// Zorba
#include <zorba/base64.h>
+#include <zorba/diagnostic_list.h>
#include <zorba/empty_sequence.h>
-#include <zorba/diagnostic_list.h>
-#include <zorba/file.h>
#include <zorba/serializer.h>
#include <zorba/singleton_item_sequence.h>
-#include <zorba/util/path.h>
+#include <zorba/transcode_stream.h>
#include <zorba/user_exception.h>
-#include <zorba/transcode_stream.h>
+#include <zorba/util/fs_util.h>
+#include <zorba/util/stream_util.h>
+// local
#include "file_module.h"
-
-namespace zorba { namespace filemodule {
+namespace zorba {
+namespace filemodule {
//*****************************************************************************
@@ -45,129 +48,87 @@
ItemSequence_t
CreateDirectoryFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lFileStr = getFilePathString(aArgs, 0);
- File_t lFile = File::createFile(lFileStr.c_str());
-
- // precondition
- if (lFile->isFile()) {
- raiseFileError("FOFL0002", "A file already exists at this path", lFile->getFilePath());
- }
-
- // actual mkdir
+ String const path( getFilePathString( aArgs, 0 ) );
+
+ if ( fs::get_type( path ) )
+ raiseFileError( "FOFL0002", "file already exists", path );
+
try {
- lFile->mkdir(true);
- } catch (ZorbaException const& ze) {
- std::stringstream lSs;
- lSs << "An unknown error occured: " << ze.what() << "Can not create directory";
- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
- } catch (...) {
- //assert(false); if this happens errors are not proprly thrown
- raiseFileError("FOFL9999", "Can not create directory", lFile->getFilePath());
- }
-
- // postcondition
- if (!(lFile->isDirectory())) {
- raiseFileError("FOFL9999", "Can not create directory", lFile->getFilePath());
- }
-
- return ItemSequence_t(new EmptySequence());
+ fs::mkdir( path );
+ }
+ catch ( std::exception const &e ) {
+ throw raiseFileError( "FOFL9999", e.what(), path );
+ }
+
+ return ItemSequence_t( new EmptySequence() );
}
//*****************************************************************************
-DeleteFileImplFunction::DeleteFileImplFunction(const FileModule* aModule)
- : FileFunction(aModule)
+DeleteFileImplFunction::DeleteFileImplFunction(const FileModule* aModule) :
+ FileFunction(aModule)
{
}
ItemSequence_t
DeleteFileImplFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lFileStr = getFilePathString(aArgs, 0);
- File_t lFile = File::createFile(lFileStr.c_str());
-
- // precondition
- if (!lFile->exists( false )) {
- raiseFileError("FOFL0001", "A file or directory does not exist at this path", lFile->getFilePath());
- }
-
- // actual remove
+ String const path( getFilePathString( aArgs, 0 ) );
+
+ if ( !fs::get_type( path, false ) )
+ raiseFileError( "FOFL0001", "file not found", path );
+
try {
- lFile->remove();
- } catch (ZorbaException const& ze) {
- std::stringstream lSs;
- lSs << "An unknown error occured: " << ze.what() << "Can not delete file";
- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
- } catch (...) {
- //assert(false); if this happens errors are not proprly thrown
- raiseFileError("FOFL9999", "Can not delete directory", lFile->getFilePath());
- }
-
- // postcondition
- if (lFile->exists( false )) {
- raiseFileError("FOFL9999", "The file at this path could not be deleted", lFile->getFilePath());
- }
-
- return ItemSequence_t(new EmptySequence());
+ fs::remove( path );
+ }
+ catch ( std::exception const &e ) {
+ throw raiseFileError( "FOFL9999", e.what(), path );
+ }
+
+ return ItemSequence_t( new EmptySequence() );
}
//*****************************************************************************
-ReadBinaryFunction::ReadBinaryFunction(const FileModule* aModule)
- : FileFunction(aModule)
+ReadBinaryFunction::ReadBinaryFunction( FileModule const *aModule ) :
+ FileFunction( aModule )
{
}
ItemSequence_t
ReadBinaryFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lFileStr = getFilePathString(aArgs, 0);
- File_t lFile = File::createFile(lFileStr.c_str());
-
- // preconditions
- if (!lFile->exists()) {
- raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());
- }
- if (lFile->isDirectory()) {
- raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
- }
-
- // actual read
- Item lItem;
+ String const path( getFilePathString( aArgs, 0 ) );
+
+ fs::type const fs_type = fs::get_type( path );
+ if ( !fs_type )
+ raiseFileError( "FOFL0001", "file not found", path );
+ if ( fs_type != fs::file )
+ raiseFileError( "FOFL0004", "not a plain file", path );
+
try {
- std::unique_ptr<std::ifstream> lInStream;
- lInStream.reset( new std::ifstream() );
- lFile->openInputStream(*lInStream.get(), true, false);
-
- lItem = theModule->getItemFactory()->createStreamableBase64Binary(
- *lInStream.release(), &FileModule::streamReleaser, true
- );
-
- } catch (ZorbaException const& ze) {
- std::stringstream lSs;
- lSs << "An unknown error occured: " << ze.what() << "Can not read file";
- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
- } catch (...) {
- //assert(false); if this happens errors are not proprly thrown
- raiseFileError("FOFL9999", "Can not read file", lFile->getFilePath());
- }
-
- if (lItem.isNull()) {
- Item lQName = theModule->getItemFactory()->createQName("http://www.w3.org/2005/xqt-errors", "err", "XPTY0004");
- throw USER_EXCEPTION(lQName, "Error while building the base64binary item." );
- }
-
- return ItemSequence_t(new SingletonItemSequence(lItem));
+ std::unique_ptr<std::ifstream> pin(
+ new std::ifstream( path.c_str(), std::ios_base::binary )
+ );
+ Item item = theModule->getItemFactory()->createStreamableBase64Binary(
+ *pin, &FileModule::streamReleaser, true
+ );
+ pin.release();
+ return ItemSequence_t( new SingletonItemSequence( item ) );
+ }
+ catch ( std::exception const &e ) {
+ throw raiseFileError( "FOFL9999", e.what(), path );
+ }
}
//*****************************************************************************
@@ -179,47 +140,43 @@
ItemSequence_t
ReadTextFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lFileStr = getFilePathString(aArgs, 0);
- File_t lFile = File::createFile(lFileStr.c_str());
- String lEncoding("UTF-8");
-
- // preconditions
- if (!lFile->exists()) {
- raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());
- }
- if (lFile->isDirectory()) {
- raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
- }
-
- if (aArgs.size() == 2) {
- lEncoding = getEncodingArg(aArgs, 1);
- }
+ String const path( getFilePathString( aArgs, 0 ) );
+ String lEncoding( "UTF-8" );
+
+ fs::type const fs_type = fs::get_type( path );
+ if ( !fs_type )
+ raiseFileError( "FOFL0001", "file not found", path );
+ if ( fs_type != fs::file )
+ raiseFileError( "FOFL0004", "not a plain file", path );
+
+ if ( aArgs.size() == 2 )
+ lEncoding = getEncodingArg( aArgs, 1 );
zorba::Item lResult;
- std::unique_ptr<std::ifstream> lInStream;
- if ( transcode::is_necessary( lEncoding.c_str() ) )
- {
+
+ std::unique_ptr<std::ifstream> pin;
+ if ( transcode::is_necessary( lEncoding.c_str() ) ) {
try {
- lInStream.reset( new transcode::stream<std::ifstream>(lEncoding.c_str()) );
- } catch (std::invalid_argument const&)
- {
- raiseFileError("FOFL0006", "Unsupported encoding", lEncoding.c_str());
- }
- }
- else
- {
- lInStream.reset( new std::ifstream() );
- }
- lFile->openInputStream(*lInStream.get(), false, true);
+ pin.reset( new transcode::stream<std::ifstream>( lEncoding.c_str() ) );
+ }
+ catch ( std::exception const &e ) {
+ throw raiseFileError("FOFL0006", e.what(), lEncoding.c_str() );
+ }
+ } else
+ pin.reset( new std::ifstream() );
+
+ pin->open( path.c_str() );
+ skip_utf8_bom( *pin );
lResult = theModule->getItemFactory()->createStreamableString(
- *lInStream.release(), &FileModule::streamReleaser, lFileStr.c_str(), true
- );
- return ItemSequence_t(new SingletonItemSequence(lResult));
+ *pin, &FileModule::streamReleaser, path.c_str(), true
+ );
+ pin.release();
+ return ItemSequence_t( new SingletonItemSequence( lResult ) );
}
//*****************************************************************************
@@ -231,34 +188,30 @@
ItemSequence_t
ReadTextLinesFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lFileStr = getFilePathString(aArgs, 0);
- File_t lFile = File::createFile(lFileStr.c_str());
- String lEncoding("UTF-8");
-
- // preconditions
- if (!lFile->exists()) {
- raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());
- }
- if (lFile->isDirectory()) {
- raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
- }
-
- lEncoding = getEncodingArg(aArgs, 1);
-
- return ItemSequence_t(new LinesItemSequence(lFile, lEncoding, this));
+ String const path( getFilePathString( aArgs, 0 ) );
+ String const lEncoding( getEncodingArg( aArgs, 1 ) );
+
+ fs::type const fs_type = fs::get_type( path );
+ if ( !fs_type )
+ raiseFileError( "FOFL0001", "file not found", path );
+ if ( fs_type != fs::file )
+ raiseFileError( "FOFL0004", "not a plain file", path );
+
+ return ItemSequence_t( new LinesItemSequence( path, lEncoding, this ) );
}
ReadTextLinesFunction::LinesItemSequence::LinesItemSequence(
- const File_t& aFile,
- const String& aEncoding,
- const ReadTextLinesFunction* aFunc)
- : theFile(aFile),
- theEncoding(aEncoding),
- theFunc(aFunc)
+ String const &aFile,
+ String const &aEncoding,
+ ReadTextLinesFunction const *aFunc
+) :
+ theFile( aFile ),
+ theEncoding( aEncoding ),
+ theFunc( aFunc )
{
}
@@ -266,18 +219,19 @@
ReadTextLinesFunction::LinesItemSequence::getIterator()
{
return new ReadTextLinesFunction::LinesItemSequence::LinesIterator(
- theFile, theEncoding, theFunc
- );
+ theFile, theEncoding, theFunc
+ );
}
ReadTextLinesFunction::LinesItemSequence::LinesIterator::LinesIterator(
- const File_t& aFile,
- const String& aEncoding,
- const ReadTextLinesFunction* aFunc)
- : theFile(aFile),
- theEncoding(aEncoding),
- theFunc(aFunc),
- theStream(0)
+ String const &aFile,
+ String const &aEncoding,
+ ReadTextLinesFunction const *aFunc
+) :
+ theFile(aFile),
+ theEncoding(aEncoding),
+ theFunc(aFunc),
+ theStream(0)
{
}
@@ -289,42 +243,32 @@
void
ReadTextLinesFunction::LinesItemSequence::LinesIterator::open()
{
- if ( transcode::is_necessary( theEncoding.c_str() ) )
- {
- try
- {
- theStream = new transcode::stream<std::ifstream>(theEncoding.c_str());
- }
- catch (std::invalid_argument const& e)
- {
- theFunc->raiseFileError("FOFL0006", "Unsupported encoding", theEncoding.c_str());
- }
- }
- else
- {
+ if ( transcode::is_necessary( theEncoding.c_str() ) ) {
+ try {
+ theStream = new transcode::stream<std::ifstream>( theEncoding.c_str() );
+ }
+ catch ( std::invalid_argument const &e ) {
+ theFunc->raiseFileError( "FOFL0006", e.what(), theEncoding.c_str() );
+ }
+ } else
theStream = new std::ifstream();
- }
- theFile->openInputStream(*theStream, false, true);
+
+ theStream->open( theFile.c_str() );
}
bool
ReadTextLinesFunction::LinesItemSequence::LinesIterator::next(Item& aRes)
{
- if (!theStream || !theStream->good())
+ if ( !theStream || !theStream->good() )
return false;
- std::string lStr;
- getline(*theStream, lStr);
+ std::string s;
+ getline( *theStream, s );
+ if ( theStream->bad() )
+ return false;
- if (theStream->bad())
- {
- return false;
- }
- else
- {
- aRes = theFunc->theModule->getItemFactory()->createString(lStr);
- return true;
- }
+ aRes = theFunc->theModule->getItemFactory()->createString( s );
+ return true;
}
void
@@ -342,220 +286,176 @@
//*****************************************************************************
-ExistsFunction::ExistsFunction(const FileModule* aModule)
- : FileFunction(aModule)
+ExistsFunction::ExistsFunction(const FileModule* aModule) :
+ FileFunction( aModule )
{
}
ItemSequence_t
ExistsFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String const lFileStr = getFilePathString(aArgs, 0);
- bool const lFollowSymlinks = getItem(aArgs, 1).getBooleanValue();
-
- File_t lFile = File::createFile(lFileStr.c_str());
- bool const lFileExists = lFile->exists(lFollowSymlinks);
-
- return ItemSequence_t(new SingletonItemSequence(
- theModule->getItemFactory()->createBoolean(lFileExists)));
+ String const path = getFilePathString( aArgs, 0 );
+ bool const follow_symlink = getItem( aArgs, 1 ).getBooleanValue();
+ bool const exists = !!fs::get_type( path, follow_symlink );
+ return ItemSequence_t(
+ new SingletonItemSequence(
+ theModule->getItemFactory()->createBoolean( exists )
+ )
+ );
}
//*****************************************************************************
-IsDirectoryFunction::IsDirectoryFunction(const FileModule* aModule)
- : FileFunction(aModule)
+IsDirectoryFunction::IsDirectoryFunction( FileModule const *aModule ) :
+ FileFunction( aModule )
{
}
ItemSequence_t
IsDirectoryFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- bool lResult = false;
- String lFileStr = getFilePathString(aArgs, 0);
-
- File_t lFile = File::createFile(lFileStr.c_str());
- if (lFile->isDirectory()) {
- lResult = true;
- }
- return ItemSequence_t(new SingletonItemSequence(
- theModule->getItemFactory()->createBoolean(lResult)));
+ String const path( getFilePathString( aArgs, 0 ) );
+ bool const is_directory = fs::get_type( path ) == fs::directory;
+ return ItemSequence_t(
+ new SingletonItemSequence(
+ theModule->getItemFactory()->createBoolean( is_directory )
+ )
+ );
}
//*****************************************************************************
-IsFileFunction::IsFileFunction(const FileModule* aModule)
- : FileFunction(aModule)
+IsFileFunction::IsFileFunction( FileModule const *aModule ) :
+ FileFunction( aModule )
{
}
ItemSequence_t
IsFileFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- bool lResult = false;
- String lFileStr = getFilePathString(aArgs, 0);
-
- File_t lFile = File::createFile(lFileStr.c_str());
- if (lFile->isFile()) {
- lResult = true;
- }
- return ItemSequence_t(new SingletonItemSequence(
- theModule->getItemFactory()->createBoolean(lResult)));
+ String const path( getFilePathString( aArgs, 0 ) );
+ bool const is_file = fs::get_type( path ) == fs::file;
+ return ItemSequence_t(
+ new SingletonItemSequence(
+ theModule->getItemFactory()->createBoolean( is_file )
+ )
+ );
}
//*****************************************************************************
-IsSymlinkFunction::IsSymlinkFunction(const FileModule* aModule)
- : FileFunction(aModule)
+IsSymlinkFunction::IsSymlinkFunction( FileModule const *aModule ) :
+ FileFunction( aModule )
{
}
ItemSequence_t
IsSymlinkFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- bool lResult = false;
- String lFileStr = getFilePathString(aArgs, 0);
-
- File_t lFile = File::createFile(lFileStr.c_str());
- if (lFile->isLink()) {
- lResult = true;
- }
- return ItemSequence_t(new SingletonItemSequence(
- theModule->getItemFactory()->createBoolean(lResult)));
+ String const path( getFilePathString( aArgs, 0 ) );
+ bool const is_symlink = fs::get_type( path, false ) == fs::link;
+ return ItemSequence_t(
+ new SingletonItemSequence(
+ theModule->getItemFactory()->createBoolean( is_symlink )
+ )
+ );
}
//*****************************************************************************
-CopyFileImplFunction::CopyFileImplFunction(const FileModule* aModule)
- : FileFunction(aModule)
+CopyFileImplFunction::CopyFileImplFunction( FileModule const *aModule ) :
+ FileFunction( aModule )
{
}
ItemSequence_t
CopyFileImplFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lSrcFileStr = getFilePathString(aArgs, 0);
- File_t lSrcFile = File::createFile(lSrcFileStr.c_str());
- String lDstStr = getFilePathString(aArgs, 1);
- File_t lDst = File::createFile(lDstStr.c_str());
-
- // preconditions
- if (!lSrcFile->exists()) {
- raiseFileError("FOFL0001", "A file does not exist at this path", lSrcFile->getFilePath());
- }
- // is this a file? (the recursive version is implemented in XQuery)
- if (lSrcFile->isDirectory()) {
- raiseFileError("FOFL0004", "This operation is non-recursive. The source path points to a directory", lSrcFile->getFilePath());
- }
-
- // do we copy into a directory?
- if (lDst->isDirectory()) {
- lDstStr = lDst->getFilePath();
- String lSrcPath = lSrcFile->getFilePath();
- int lLastSep = lSrcPath.rfind(File::getDirectorySeparator());
- String lName = lSrcPath.substr(lLastSep);
- lDstStr = lDstStr.append(lName.c_str());
- lDst = File::createFile(lDstStr.c_str());
- }
-
- // is the destination still is a directory?
- if (lDst->isDirectory()) {
- raiseFileError("FOFL0002", "The destination path already exists", lSrcFile->getFilePath());
- }
-
- // do we copy a file to its own location?
- if (lSrcFile->getFilePath() == lDst->getFilePath()) {
- raiseFileError("FOFL9999", "The source and destination paths can not point to the same file", lSrcFile->getFilePath());
- }
-
- // actual copy
+ String const src_path( getFilePathString( aArgs, 0 ) );
+ String dst_path( getFilePathString( aArgs, 1 ) );
+
+ fs::type const src_type = fs::get_type( src_path );
+ if ( !src_type )
+ raiseFileError( "FOFL0001", "file not found", src_path );
+ if ( src_type != fs::file )
+ raiseFileError( "FOFL0004", "not a plain file", src_path );
+
+ fs::type dst_type = fs::get_type( dst_path );
+ if ( dst_type == fs::directory ) { // we are copying into a directory
+ fs::append( dst_path, fs::base_name( src_path ) );
+ dst_type = fs::get_type( dst_path );
+ if ( dst_type == fs::directory )
+ raiseFileError( "FOFL0002", "path already exists", dst_path );
+ }
+
+ if ( src_path == dst_path )
+ raiseFileError( "FOFL9999", "source and destination paths must not be equal", src_path );
+
try {
-
- // open the output stream in the desired write mode
- std::ifstream lInStream;
- std::ofstream lOutStream;
- lSrcFile->openInputStream(lInStream, true, false);
- lDst->openOutputStream(lOutStream, true, false);
-
- // copy the data
- char lBuf[1024];
- while (!lInStream.eof()) {
- lInStream.read(lBuf, 1024);
- lOutStream.write(lBuf, lInStream.gcount());
+ std::ifstream fin( src_path.c_str(), std::ios_base::binary );
+ std::ofstream fout( dst_path.c_str(), std::ios_base::binary | std::ios_base::trunc );
+ char buf[ 8192 ];
+ while ( !fin.eof() ) {
+ fin.read( buf, sizeof buf );
+ fout.write( buf, fin.gcount() );
}
-
- // close the streams
- lInStream.close();
- lOutStream.close();
-
- } catch (ZorbaException const& ze) {
- std::stringstream lSs;
- lSs << "An unknown error occured: " << ze.what() << "Can not copy file";
- raiseFileError("FOFL9999", lSs.str(), lSrcFile->getFilePath());
- } catch (...) {
- //assert(false); if this happens errors are not proprly thrown
- raiseFileError("FOFL9999", "Can not copy file", lSrcFile->getFilePath());
- }
-
- return ItemSequence_t(new EmptySequence());
+ }
+ catch ( std::exception const &e ) {
+ throw raiseFileError( "FOFL9999", e.what(), src_path );
+ }
+
+ return ItemSequence_t( new EmptySequence() );
}
//*****************************************************************************
-ListFunction::ListFunction(const FileModule* aModule)
- : FileFunction(aModule)
+ListFunction::ListFunction( FileModule const *aModule ) :
+ FileFunction( aModule )
{
}
ItemSequence_t
ListFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lFileStr = getFilePathString(aArgs, 0);
- File_t lFile = File::createFile(lFileStr.c_str());
-
- // precondition
- if (!lFile->isDirectory()) {
- raiseFileError("FOFL0003", "The specified path does not point to a directory", lFile->getFilePath());
- }
-
- // actual list
+ String const path( getFilePathString( aArgs, 0 ) );
+
+ if ( fs::get_type( path ) != fs::directory )
+ raiseFileError( "FOFL0003", "path is not a directory", path );
+
try {
- DirectoryIterator_t lIter = lFile->files();
- return ItemSequence_t(new IteratorBackedItemSequence(lIter, theModule->getItemFactory()));
- } catch (ZorbaException const& ze) {
- std::stringstream lSs;
- lSs << "An unknown error occured: " << ze.what() << "Can not list directory";
- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
- } catch (...) {
- //assert(false); if this happens errors are not proprly thrown
- raiseFileError("FOFL9999", "Can not list directory", lFile->getFilePath());
- }
-
- // dummy, this will never be called
- return ItemSequence_t(new EmptySequence());
+ return ItemSequence_t(
+ new IteratorBackedItemSequence( path, theModule->getItemFactory() )
+ );
+ }
+ catch ( std::exception const &e ) {
+ throw raiseFileError( "FOFL9999", e.what(), path );
+ }
}
ListFunction::IteratorBackedItemSequence::IteratorBackedItemSequence(
- DirectoryIterator_t& aIter,
- ItemFactory* aFactory)
- : theIterator(aIter), theItemFactory(aFactory)
+ String const& path,
+ ItemFactory* aFactory
+) :
+ theIterator( path ),
+ theItemFactory( aFactory )
{
is_open = false;
open_count = 0;
@@ -573,7 +473,7 @@
void ListFunction::IteratorBackedItemSequence::open()
{
if (open_count) {
- theIterator->reset();
+ theIterator.reset();
}
open_count++;
is_open = true;
@@ -592,64 +492,57 @@
bool
ListFunction::IteratorBackedItemSequence::next(Item& lItem)
{
- std::string lPath;
- if (!theIterator->next(lPath)) {
+ if ( !theIterator.next() )
return false;
- }
- String lUriStr(lPath.c_str());
- lItem = theItemFactory->createString(lUriStr);
+ String lUriStr( theIterator.entry_name() );
+ lItem = theItemFactory->createString( lUriStr );
return true;
}
//*****************************************************************************
-LastModifiedFunction::LastModifiedFunction(const FileModule* aModule)
- : FileFunction(aModule)
+LastModifiedFunction::LastModifiedFunction(const FileModule* aModule) :
+ FileFunction(aModule)
{
}
ItemSequence_t
LastModifiedFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lFileStr = getFilePathString(aArgs, 0);
- File_t lFile = File::createFile(lFileStr.c_str());
-
- // precondition
- if (!lFile->exists()) {
- raiseFileError("FOFL0001", "A file or directory does not exist at this path", lFile->getFilePath());
- }
-
- // actual last modified
+ String const path( getFilePathString( aArgs, 0 ) );
+
+ fs::info info;
+ if ( !fs::get_type( path, &info ) )
+ raiseFileError( "FOFL0001", "file not found", path );
+
try {
- time_t lTime = lFile->lastModified();
+ time_t lTime = info.mtime;
// result of localtime needs to be copied.
// Otherwise, nasty side effecs do happen
struct tm lT(*localtime(&lTime));
int gmtOffset = LastModifiedFunction::getGmtOffset();
- return ItemSequence_t(new SingletonItemSequence(
- theModule->getItemFactory()->createDateTime(1900 + lT.tm_year,
- lT.tm_mon,
- lT.tm_mday,
- lT.tm_hour,
- lT.tm_min,
- lT.tm_sec,
- gmtOffset)));
- } catch (ZorbaException const& ze) {
- std::stringstream lSs;
- lSs << "An unknown error occured: " << ze.what() << "Can not retrieve the last modification timestamp of";
- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
- } catch (...) {
- //assert(false); if this happens errors are not proprly thrown
- raiseFileError("FOFL9999", "Can not retrieve the last modification timestamp of", lFile->getFilePath());
- }
-
- // dummy, this will never be called
- return ItemSequence_t(new EmptySequence());
+ return ItemSequence_t(
+ new SingletonItemSequence(
+ theModule->getItemFactory()->createDateTime(
+ 1900 + lT.tm_year,
+ lT.tm_mon,
+ lT.tm_mday,
+ lT.tm_hour,
+ lT.tm_min,
+ lT.tm_sec,
+ gmtOffset
+ )
+ )
+ );
+ }
+ catch ( std::exception const &e ) {
+ throw raiseFileError( "FOFL9999", e.what(), path );
+ }
}
int
@@ -675,36 +568,20 @@
ItemSequence_t
SizeFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lFileStr = getFilePathString(aArgs, 0);
- File_t lFile = File::createFile(lFileStr.c_str());
-
- // preconditions
- if (!lFile->exists()) {
- raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());
- }
- if (lFile->isDirectory()) {
- raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
- }
-
- // actual size
- File::FileSize_t lFs = -1;
- try {
- lFs = lFile->getSize();
- } catch (ZorbaException const& ze) {
- std::stringstream lSs;
- lSs << "An unknown error occured: " << ze.what() << "Can not retrieve the file size of";
- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
- } catch (...) {
- //assert(false); if this happens errors are not proprly thrown
- raiseFileError("FOFL9999", "Can not retrieve the file size of", lFile->getFilePath());
- }
+ String const path( getFilePathString( aArgs, 0 ) );
+
+ fs::info info;
+ if ( !fs::get_type( path, &info ) )
+ raiseFileError( "FOFL0001", "file not found", path );
+ if ( info.type != fs::file )
+ raiseFileError( "FOFL0004", "not plain file", path );
return ItemSequence_t(new SingletonItemSequence(
- theModule->getItemFactory()->createInteger(lFs)));
+ theModule->getItemFactory()->createInteger(info.size)));
}
//*****************************************************************************
@@ -716,11 +593,16 @@
ItemSequence_t
PathSeparator::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(FileFunction::pathSeparator())));
+ String const path_separator( 1, fs::path_separator );
+ return ItemSequence_t(
+ new SingletonItemSequence(
+ theModule->getItemFactory()->createString( path_separator )
+ )
+ );
}
//*****************************************************************************
@@ -732,11 +614,16 @@
ItemSequence_t
DirectorySeparator::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(FileFunction::directorySeparator())));
+ String const dir_separator( 1, fs::dir_separator );
+ return ItemSequence_t(
+ new SingletonItemSequence(
+ theModule->getItemFactory()->createString( dir_separator )
+ )
+ );
}
//*****************************************************************************
@@ -748,11 +635,11 @@
ItemSequence_t
ResolvePathFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lPathStr = getFilePathString(aArgs, 0);
+ String lPathStr = getFilePathString( aArgs, 0 );
String lResult = pathToOSPath(lPathStr);
return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(lResult)));
@@ -766,17 +653,28 @@
}
ItemSequence_t
-PathToNativeFunction::evaluate(const ExternalFunction::Arguments_t& args,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+PathToNativeFunction::evaluate(
+ ExternalFunction::Arguments_t const &args,
+ StaticContext const*,
+ DynamicContext const* ) const
{
Item pathItem;
Iterator_t arg0_iter = args[0]->getIterator();
arg0_iter->open();
arg0_iter->next(pathItem);
arg0_iter->close();
- String osPath = filesystem_path::normalize_path(pathItem.getStringValue().c_str());
- return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(osPath)));
+ String const path( pathItem.getStringValue() );
+ try {
+ String const osPath( fs::normalize_path( path ) );
+ return ItemSequence_t(
+ new SingletonItemSequence(
+ theModule->getItemFactory()->createString( osPath )
+ )
+ );
+ }
+ catch ( std::invalid_argument const &e ) {
+ throw raiseFileError( "FOFL9999", e.what(), path );
+ }
}
//*****************************************************************************
@@ -788,11 +686,11 @@
ItemSequence_t
PathToUriFunction::evaluate(
- const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ ExternalFunction::Arguments_t const &aArgs,
+ StaticContext const*,
+ DynamicContext const* ) const
{
- String lPathStr = getFilePathString(aArgs, 0);
+ String lPathStr = getFilePathString( aArgs, 0 );
String lResult = pathToUriString(lPathStr);
return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createAnyURI(lResult)));
@@ -869,7 +767,8 @@
//*****************************************************************************
-} /* namespace filemodule */ } /* namespace zorba */
+} // namespace filemodule
+} // namespace zorba
#ifdef WIN32
# define DLL_EXPORT __declspec(dllexport)
=== modified file 'modules/org/expath/ns/file.xq.src/file.h'
--- modules/org/expath/ns/file.xq.src/file.h 2013-03-06 02:54:03 +0000
+++ modules/org/expath/ns/file.xq.src/file.h 2013-06-03 23:16:28 +0000
@@ -16,6 +16,8 @@
#ifndef ZORBA_FILEMODULE_FILE_H
#define ZORBA_FILEMODULE_FILE_H
+#include <zorba/util/fs_util.h>
+
#include "file_function.h"
namespace zorba {
@@ -107,7 +109,7 @@
public:
IteratorBackedItemSequence(
- DirectoryIterator_t& aIter,
+ String const& path,
zorba::ItemFactory* aFactory);
virtual ~IteratorBackedItemSequence();
@@ -123,7 +125,7 @@
private:
bool is_open;
int open_count;
- DirectoryIterator_t theIterator;
+ fs::iterator theIterator;
ItemFactory* theItemFactory;
};
};
@@ -349,14 +351,14 @@
class LinesItemSequence : public ItemSequence
{
protected:
- File_t theFile;
+ String theFile;
String theEncoding;
const ReadTextLinesFunction* theFunc;
class LinesIterator : public Iterator
{
protected:
- const File_t& theFile;
+ const String& theFile;
const String& theEncoding;
const ReadTextLinesFunction* theFunc;
@@ -364,7 +366,7 @@
public:
LinesIterator(
- const File_t&,
+ const String&,
const String&,
const ReadTextLinesFunction*);
@@ -385,7 +387,7 @@
public:
LinesItemSequence(
- const File_t& aFile,
+ const String& aFile,
const String& aEncoding,
const ReadTextLinesFunction*);
=== modified file 'modules/org/expath/ns/file.xq.src/file_function.cpp'
--- modules/org/expath/ns/file.xq.src/file_function.cpp 2013-02-07 17:24:36 +0000
+++ modules/org/expath/ns/file.xq.src/file_function.cpp 2013-06-03 23:16:28 +0000
@@ -20,11 +20,10 @@
#include <zorba/empty_sequence.h>
#include <zorba/diagnostic_list.h>
-#include <zorba/file.h>
#include <zorba/serializer.h>
#include <zorba/store_consts.h>
#include <zorba/user_exception.h>
-#include <zorba/util/path.h>
+#include <zorba/util/fs_util.h>
#include <zorba/xquery_functions.h>
#include <zorba/singleton_item_sequence.h>
#include <zorba/zorba.h>
@@ -42,23 +41,6 @@
#include <unistd.h>
#endif
-static zorba::String getCurrentPath()
-{
-#ifdef WIN32
- wchar_t* wbuffer = _wgetcwd(NULL, 0);
- char *buffer = (char*)malloc(1024);
- WideCharToMultiByte(CP_UTF8, 0, wbuffer, -1, buffer, 1024, NULL, NULL);
-#else
- char buffer[2048];
- getcwd(buffer, 2048);
-#endif
- zorba::String result(buffer);
-#ifdef WIN32
- free(buffer);
-#endif
- return result;
-}
-
namespace zorba { namespace filemodule {
FileFunction::FileFunction(const FileModule* aModule)
@@ -70,16 +52,18 @@
{
}
-void
+int
FileFunction::raiseFileError(
- const std::string& aQName,
- const std::string& aMessage,
- const std::string& aPath) const
+ char const *aQName,
+ char const *aMessage,
+ String const &aPath ) const
{
- std::stringstream lErrorMessage;
- lErrorMessage << aMessage << ": " << aPath;
- Item lQName = theModule->getItemFactory()->createQName(getURI(), "file", aQName);
- throw USER_EXCEPTION(lQName, lErrorMessage.str());
+ Item const lQName(
+ theModule->getItemFactory()->createQName( getURI(), "file", aQName )
+ );
+ std::ostringstream lErrorMessage;
+ lErrorMessage << '"' << aPath << "\": " << aMessage;
+ throw USER_EXCEPTION( lQName, lErrorMessage.str() );
}
String
@@ -103,26 +87,22 @@
}
args_iter->close();
- return (filesystem_path::normalize_path
- (lFileArg.c_str(), getCurrentPath().c_str()));
-}
-
-String
-FileFunction::directorySeparator() {
- return File::getDirectorySeparator();
-}
-
-String
-FileFunction::pathSeparator() {
- return File::getPathSeparator();
+ try {
+ return fs::normalize_path(lFileArg, fs::curdir());
+ }
+ catch ( std::invalid_argument const &e ) {
+ throw raiseFileError( "FOFL9999", e.what(), lFileArg );
+ }
}
String
FileFunction::pathToFullOSPath(const String& aPath) const {
- File_t lFile = File::createFile(aPath.c_str());
- std::string lPath = lFile->getFilePath();
-
- return String(lPath);
+ try {
+ return fs::normalize_path( aPath );
+ }
+ catch ( std::invalid_argument const &e ) {
+ throw raiseFileError( "FOFL9999", e.what(), aPath );
+ }
}
String
@@ -147,31 +127,30 @@
String
FileFunction::pathToOSPath(const String& aPath) const {
- File_t lFile = File::createFile(aPath.c_str());
- std::string lPath = lFile->getFilePath();
-
- return String(lPath);
+ try {
+ return fs::normalize_path( aPath );
+ }
+ catch ( std::invalid_argument const &e ) {
+ throw raiseFileError( "FOFL9999", e.what(), aPath );
+ }
}
String
FileFunction::pathToUriString(const String& aPath) const {
- std::stringstream lErrorMessage;
- if(fn::starts_with(aPath,"file://")) {
+ if ( fn::starts_with( aPath,"file://" ) ) {
+ std::stringstream lErrorMessage;
lErrorMessage << "Please provide a path, not a URI";
Item lQName = theModule->getItemFactory()->createQName(
"http://www.w3.org/2005/xqt-errors",
"err",
"XPTY0004");
- throw USER_EXCEPTION(lQName, lErrorMessage.str() );
+ throw USER_EXCEPTION( lQName, lErrorMessage.str() );
}
- File_t lFile = File::createFile(aPath.c_str());
-
- std::string lPath = lFile->getFileUri();
-
-
- return String(lPath);
+ String uri( aPath );
+
+ return uri;
}
#ifdef WIN32
@@ -187,12 +166,9 @@
return false;
}
- char lDrive = aString[0];
+ char const lDrive = aString[0];
// the string is already upper case
- if (lDrive < 65 || lDrive > 90) {
- return false;
- }
- return true;
+ return lDrive >= 'A' && lDrive <= 'Z';
}
#endif
@@ -234,33 +210,26 @@
ItemSequence_t
WriterFileFunction::evaluate(
const ExternalFunction::Arguments_t& aArgs,
- const StaticContext* aSctxCtx,
- const DynamicContext* aDynCtx) const
+ const StaticContext*,
+ const DynamicContext* ) const
{
- String lFileStr = getFilePathString(aArgs, 0);
- File_t lFile = File::createFile(lFileStr.c_str());
-
- // precondition
- if (lFile->isDirectory())
- {
- raiseFileError("FOFL0004",
- "The given path points to a directory", lFile->getFilePath());
- }
-
- bool lBinary = isBinary();
- // open the output stream in the desired write mode
- std::ofstream lOutStream;
-
- // actual write
- try
- {
- lFile->openOutputStream(lOutStream, lBinary, isAppend());
- }
- catch (ZorbaException& ze)
- {
- std::stringstream lSs;
- lSs << "Can not open file for writing: " << ze.what();
- raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
+ String const lFileStr( getFilePathString(aArgs, 0) );
+
+ if ( fs::get_type( lFileStr ) != fs::file )
+ raiseFileError( "FOFL0004", "not a plain file", lFileStr );
+
+ bool const lBinary = isBinary();
+
+ std::ios_base::openmode mode = std::ios_base::out
+ | (isAppend() ? std::ios_base::app : std::ios_base::trunc);
+ if ( lBinary )
+ mode |= std::ios_base::binary;
+
+ std::ofstream lOutStream( lFileStr.c_str(), mode );
+ if ( !lOutStream ) {
+ std::ostringstream oss;
+ oss << '"' << lFileStr << "\": can not open file for writing";
+ raiseFileError( "FOFL9999", oss.str().c_str(), lFileStr );
}
// if this is a binary write
@@ -320,3 +289,4 @@
} // namespace filemodule
} // namespace zorba
+/* vim:set et sw=2 ts=2: */
=== modified file 'modules/org/expath/ns/file.xq.src/file_function.h'
--- modules/org/expath/ns/file.xq.src/file_function.h 2013-02-07 17:24:36 +0000
+++ modules/org/expath/ns/file.xq.src/file_function.h 2013-06-03 23:16:28 +0000
@@ -44,11 +44,11 @@
protected:
const FileModule* theModule;
- void
+ int
raiseFileError(
- const std::string& qName,
- const std::string& message,
- const std::string& path) const;
+ char const *qName,
+ char const *message,
+ const String& path) const;
/*
* Gets the argument on position pos as a normalised file system path.
@@ -73,12 +73,6 @@
String
pathToUriString(const String& path) const;
- static String
- directorySeparator();
-
- static String
- pathSeparator();
-
public:
FileFunction(const FileModule* module);
~FileFunction();
=== modified file 'src/api/CMakeLists.txt'
--- src/api/CMakeLists.txt 2013-04-10 10:13:31 +0000
+++ src/api/CMakeLists.txt 2013-06-03 23:16:28 +0000
@@ -63,11 +63,6 @@
module_info_impl.cpp
)
-IF (ZORBA_WITH_FILE_ACCESS)
- LIST(APPEND API_SRCS
- fileimpl.cpp)
-ENDIF (ZORBA_WITH_FILE_ACCESS)
-
IF (NOT ZORBA_NO_FULL_TEXT)
LIST(APPEND API_SRCS
stemmer.cpp
=== removed file 'src/api/fileimpl.cpp'
--- src/api/fileimpl.cpp 2013-04-19 22:25:21 +0000
+++ src/api/fileimpl.cpp 1970-01-01 00:00:00 +0000
@@ -1,404 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "stdafx.h"
-
-#include "fileimpl.h"
-
-#include <fstream>
-
-#include <zorba/diagnostic_handler.h>
-#include <zorba/util/file.h>
-
-#include <runtime/util/flowctl_exception.h>
-
-#include "diagnostics/xquery_diagnostics.h"
-
-#ifdef WIN32
-#include <util/ascii_util.h>
-#endif
-
-#include "util/uri_util.h"
-#include "zorbaimpl.h"
-
-namespace zorba {
-
-DirectoryIteratorImpl::DirectoryIteratorImpl(std::string const& aPath) :
- theInternalDirIter( aPath.c_str() )
-{
-}
-
-bool
-DirectoryIteratorImpl::next(std::string& aPathStr) const
-{
- if (!theInternalDirIter.next()) {
- return false;
- }
-
- // get the current pointed entry
- aPathStr = theInternalDirIter.entry_name();
-
- return true;
-}
-
-void DirectoryIteratorImpl::reset()
-{
- theInternalDirIter.reset();
-}
-
-FileImpl::FileImpl(std::string const& path)
- : theDiagnosticHandler(new DiagnosticHandler())
-{
- theInternalFile = new file(path
-#ifdef WIN32
- , filesystem_path::CONVERT_SLASHES
-#endif
- );
-}
-
-FileImpl::~FileImpl()
-{
- delete theInternalFile;
- delete theDiagnosticHandler;
-}
-
-File_t
-File::createFile(const std::string& path)
-{
- return new FileImpl(path);
-}
-
-const char*
-File::getDirectorySeparator()
-{
- return filesystem_path::get_directory_separator();
-}
-
-const char*
-File::getPathSeparator()
-{
- return filesystem_path::get_path_separator();
-}
-
-const std::string
-FileImpl::getFilePath() const
-{
- std::string lResult;
-
- ZORBA_TRY
- lResult = theInternalFile->get_path();
- ZORBA_CATCH
-
- return lResult;
-}
-
-const std::string
-FileImpl::getFileUri() const
-{
- std::string lPath;
-
- ZORBA_TRY
- lPath = theInternalFile->get_path();
-#ifdef WIN32
- ascii::replace_all( lPath, '\\', '/' );
-#endif
-
- std::stringstream lEncodedResult;
- lEncodedResult << "file:///";
-
- size_t lCurrentPos = 0;
- size_t lNextSlashPos = lPath.find_first_of("/");
- while (lNextSlashPos != std::string::npos) {
- String lEncodedSegment(lPath.substr(lCurrentPos, lNextSlashPos - lCurrentPos));
- uri::encode( lEncodedSegment );
- lEncodedResult << lEncodedSegment << "/";
- lCurrentPos = lNextSlashPos + 1;
- lNextSlashPos = lPath.find_first_of("/", lNextSlashPos + 1);
- }
-
- String lEncodedSegment(lPath.substr(lCurrentPos));
- uri::encode( lEncodedSegment );
- lEncodedResult << lEncodedSegment;
-
- lPath = lEncodedResult.str();
- ZORBA_CATCH
-
- return lPath;
-}
-
-bool
-FileImpl::isDirectory( bool follow_symlinks ) const
-{
- bool lResult = false;
-
- ZORBA_TRY
- lResult = theInternalFile->is_directory( follow_symlinks )
- || theInternalFile->is_volume( follow_symlinks )
- || theInternalFile->is_root();
- ZORBA_CATCH
-
- return lResult;
-}
-
-bool
-FileImpl::isFile( bool follow_symlinks ) const
-{
- bool lResult = false;
-
- ZORBA_TRY
- lResult = theInternalFile->is_file( follow_symlinks ) || theInternalFile->is_link();
- ZORBA_CATCH
-
- return lResult;
-}
-
-bool
-FileImpl::isLink() const
-{
- bool lResult = false;
-
- ZORBA_TRY
- lResult = theInternalFile->is_link();
- ZORBA_CATCH
-
- return lResult;
-}
-
-bool
-FileImpl::isVolume( bool follow_symlinks ) const
-{
- bool lResult = false;
-
- ZORBA_TRY
- lResult = theInternalFile->is_volume( follow_symlinks );
- ZORBA_CATCH
-
- return lResult;
-}
-
-bool
-FileImpl::isInvalid() const
-{
- bool lResult = false;
-
- ZORBA_TRY
- lResult = theInternalFile->is_invalid();
- ZORBA_CATCH
-
- return lResult;
-}
-
-bool
-FileImpl::exists( bool follow_symlinks ) const
-{
- bool lResult = false;
-
- ZORBA_TRY
- lResult = theInternalFile->exists( follow_symlinks );
- ZORBA_CATCH
-
- return lResult;
-}
-
-void
-FileImpl::remove()
-{
- ZORBA_TRY
- if (theInternalFile->is_directory()) {
- theInternalFile->rmdir(false);
- } else {
- theInternalFile->remove(false);
- }
- ZORBA_CATCH
-}
-
-bool
-FileImpl::create()
-{
- bool lResult = false;
-
- ZORBA_TRY
- // if the file/dir exist, return false
- if (theInternalFile->exists()) {
- return false;
- }
-
- theInternalFile->create();
-
- // if the file does not exist, return false
- if (!theInternalFile->exists() || !theInternalFile->is_file()) {
- return false;
- }
-
- lResult = true;
- ZORBA_CATCH
-
- return lResult;
-}
-
-bool
-FileImpl::rename(std::string const& newpath)
-{
- bool lResult = false;
-
- ZORBA_TRY
- // if the file/dir does not exist, return false
- if (!theInternalFile->exists()) {
- return false;
- }
- // if the new path is already used, return false
- file lNewFile(newpath);
- if (lNewFile.exists()) {
- return false;
- }
-
- theInternalFile->rename(newpath);
-
- // if the file does not exist, return false
- if (!lNewFile.exists()) {
- return false;
- }
-
- lResult = true;
- ZORBA_CATCH
-
- return lResult;
-}
-
-File::FileSize_t
-FileImpl::getSize() const
-{
- ZORBA_TRY
- return theInternalFile->get_size();
- ZORBA_CATCH
- assert(false);
- return -1;
-}
-
-void
-FileImpl::mkdir(bool aRecursive)
-{
- ZORBA_TRY
- if (aRecursive) {
- theInternalFile->deep_mkdir();
- } else {
- theInternalFile->mkdir();
- }
- ZORBA_CATCH
-}
-
-DirectoryIterator_t
-FileImpl::files() const
-{
- return new DirectoryIteratorImpl(theInternalFile->get_path());
-}
-
-void
-FileImpl::openInputStream(std::ifstream& aInStream, bool binary, bool trimByteOrderMark) const
-{
- ZORBA_TRY
- std::string lPath(theInternalFile->get_path());
-
- if (!theInternalFile->exists())
- throw XQUERY_EXCEPTION(
- err::FODC0002, ERROR_PARAMS( lPath, ZED( FileNotFoundOrReadable ) )
- );
- if (!theInternalFile->is_file())
- throw XQUERY_EXCEPTION(
- err::FODC0002, ERROR_PARAMS( lPath, ZED( NotPlainFile ) )
- );
-
- std::ios_base::openmode lMode = std::ifstream::in;
- if (binary) {
- lMode |= std::ios_base::binary;
- }
-#ifndef WIN32
- aInStream.open(lPath.c_str(), lMode);
-#else
- WCHAR wpath_str[1024];
- wpath_str[0] = 0;
- if(MultiByteToWideChar(CP_UTF8,
- 0, lPath.c_str(), -1,
- wpath_str, sizeof(wpath_str)/sizeof(WCHAR)) == 0)
- {//probably there is some invalid utf8 char, try the Windows ACP
- MultiByteToWideChar(CP_ACP,
- 0, lPath.c_str(), -1,
- wpath_str, sizeof(wpath_str)/sizeof(WCHAR));
- }
- aInStream.open(wpath_str, lMode);
-#endif
-
- if (aInStream.is_open() == false)
- throw XQUERY_EXCEPTION(
- err::FODC0002, ERROR_PARAMS( lPath, ZED( FileNotFoundOrReadable ) )
- );
-
- if (trimByteOrderMark) {
- char lBuf[3];
- aInStream.read(lBuf, 3);
- if (!aInStream.good() || lBuf[0] != (char)0xEF || lBuf[1] != (char)0xBB || lBuf[2] != (char)0xBF ) {
- aInStream.seekg(0);
- }
- }
- ZORBA_CATCH
-}
-
-void
-FileImpl::openOutputStream(std::ofstream& aOutStream, bool binary, bool append) const
-{
- ZORBA_TRY
- std::string lPath(theInternalFile->get_path());
-
- if (theInternalFile->exists() && !theInternalFile->is_file())
- throw XQUERY_EXCEPTION(
- err::FODC0002, ERROR_PARAMS( lPath, ZED( NotPlainFile ) )
- );
-
- std::ios_base::openmode lMode = std::ifstream::out;
- lMode |= append ? std::ios_base::app : std::ios_base::trunc;
- if (binary) {
- lMode |= std::ios_base::binary;
- }
-#ifndef WIN32
- aOutStream.open(lPath.c_str(), lMode);
-#else
- WCHAR wpath_str[1024];
- wpath_str[0] = 0;
- if(MultiByteToWideChar(CP_UTF8,
- 0, lPath.c_str(), -1,
- wpath_str, sizeof(wpath_str)/sizeof(WCHAR)) == 0)
- {//probably there is some invalid utf8 char, try the Windows ACP
- MultiByteToWideChar(CP_ACP,
- 0, lPath.c_str(), -1,
- wpath_str, sizeof(wpath_str)/sizeof(WCHAR));
- }
- aOutStream.open(wpath_str, lMode);
-#endif
-
- if (aOutStream.is_open() == false)
- throw XQUERY_EXCEPTION(
- err::FODC0002, ERROR_PARAMS( lPath, ZED( FileNotFoundOrReadable ) )
- );
- ZORBA_CATCH
-}
-
-time_t
-FileImpl::lastModified() const
-{
- return theInternalFile->lastModified();
-}
-
-} // namespace zorba
-/* vim:set et sw=2 ts=2: */
=== removed file 'src/api/fileimpl.h'
--- src/api/fileimpl.h 2013-04-19 22:25:21 +0000
+++ src/api/fileimpl.h 1970-01-01 00:00:00 +0000
@@ -1,94 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-#ifndef XQP_FILE_IMPL_H
-#define XQP_FILE_IMPL_H
-
-#include <iostream>
-#include <zorba/file.h>
-
-#include "util/fs_util.h"
-
-namespace zorba {
-
- class file;
- class DiagnosticHandler;
-
-
-class DirectoryIteratorImpl : public DirectoryIterator
-{
-private:
-
- mutable fs::iterator theInternalDirIter;
-
-public:
-
- DirectoryIteratorImpl(std::string const& aPath);
-
- bool next(std::string& aPathStr) const;
- void reset();
-};
-
-
-class FileImpl : public File
-{
-private:
-
- zorba::file* theInternalFile;
-
- DiagnosticHandler* theDiagnosticHandler;
-
-public:
-
- FileImpl(std::string const& _path);
-
- ~FileImpl();
-
-
-public: // public methods
-
- const std::string getFilePath() const;
- const std::string getFileUri() const;
-
- bool isDirectory( bool follow_symlinks = true ) const;
- bool isFile( bool follow_symlinks = true ) const;
- bool isLink() const;
- bool isVolume( bool follow_symlinks = true ) const;
- bool isInvalid() const; // deprecated
- bool exists( bool follow_symlinks = true ) const;
-
- void remove();
- bool create();
- bool rename(std::string const& newpath);
-
- FileSize_t getSize() const;
-
- void mkdir(bool recursive = true);
-
- DirectoryIterator_t files() const;
-
- void openInputStream(std::ifstream& aInStream, bool binary, bool trimByteOrderMark) const;
-
- void openOutputStream(std::ofstream& aOutStream, bool binary, bool append) const;
-
- time_t lastModified() const;
-};
-
-
-} /* namespace zorba */
-
-#endif
-/* vim:set et sw=2 ts=2: */
=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2013-03-25 23:02:19 +0000
+++ src/api/staticcontextimpl.cpp 2013-06-03 23:16:28 +0000
@@ -23,7 +23,7 @@
#include <zorba/diagnostic_handler.h>
#include <zorba/static_context_consts.h>
#include <zorba/typeident.h>
-#include <zorba/util/path.h>
+#include <zorba/util/fs_util.h>
#include <zorba/empty_sequence.h>
#include <zorba/singleton_item_sequence.h>
@@ -1131,9 +1131,9 @@
{
aInternalStrings.push_back(Unmarshaller::getInternalString(*lIter).c_str());
zstring& lPath = aInternalStrings.back();
- if (lPath[lPath.length() - 1] != *filesystem_path::get_directory_separator())
+ if (lPath[lPath.length() - 1] != fs::dir_separator)
{
- lPath.append(filesystem_path::get_directory_separator());
+ lPath += fs::dir_separator;
}
}
}
=== modified file 'src/api/stemmer_wrappers.cpp'
--- src/api/stemmer_wrappers.cpp 2013-02-07 17:24:36 +0000
+++ src/api/stemmer_wrappers.cpp 2013-06-03 23:16:28 +0000
@@ -19,9 +19,9 @@
#ifndef ZORBA_NO_FULL_TEXT
+#include <zorba/internal/cxx_util.h>
#include "api/unmarshaller.h"
#include "diagnostics/assert.h"
-#include "util/cxx_util.h"
#include "stemmer_wrappers.h"
=== modified file 'src/api/thesaurus_wrappers.cpp'
--- src/api/thesaurus_wrappers.cpp 2013-02-07 17:24:36 +0000
+++ src/api/thesaurus_wrappers.cpp 2013-06-03 23:16:28 +0000
@@ -19,9 +19,9 @@
#ifndef ZORBA_NO_FULL_TEXT
+#include <zorba/internal/cxx_util.h>
#include "api/unmarshaller.h"
#include "diagnostics/assert.h"
-#include "util/cxx_util.h"
#include "thesaurus_wrappers.h"
=== modified file 'src/api/zorba_string.cpp'
--- src/api/zorba_string.cpp 2013-02-07 17:24:36 +0000
+++ src/api/zorba_string.cpp 2013-06-03 23:16:28 +0000
@@ -15,11 +15,11 @@
*/
#include "stdafx.h"
+#include <zorba/internal/cxx_util.h>
#include <zorba/zorba_string.h>
#include "api/unmarshaller.h"
#include "util/ascii_util.h"
-#include "util/cxx_util.h"
#include "util/regex.h"
#include "util/string_util.h"
#include "util/uri_util.h"
=== modified file 'src/compiler/expression/ftnode.cpp'
--- src/compiler/expression/ftnode.cpp 2013-02-07 17:24:36 +0000
+++ src/compiler/expression/ftnode.cpp 2013-06-03 23:16:28 +0000
@@ -16,11 +16,11 @@
#include "stdafx.h"
#include <zorba/error.h>
+#include <zorba/internal/cxx_util.h>
#include "diagnostics/xquery_diagnostics.h"
#include "types/casting.h"
#include "util/ascii_util.h"
-#include "util/cxx_util.h"
#include "util/indent.h"
#include "util/stl_util.h"
#include "zorbautils/locale.h"
=== modified file 'src/compiler/expression/ftnode.h'
--- src/compiler/expression/ftnode.h 2013-02-07 17:24:36 +0000
+++ src/compiler/expression/ftnode.h 2013-06-03 23:16:28 +0000
@@ -18,6 +18,7 @@
#define ZORBA_COMPILER_FTNODE_H
#include <zorba/locale.h>
+#include <zorba/internal/cxx_util.h>
#include "common/shared_types.h"
@@ -29,8 +30,6 @@
#include "runtime/base/plan_iterator.h"
-#include "util/cxx_util.h"
-
#include "zorbatypes/rchandle.h"
#include "zorbatypes/zstring.h"
=== modified file 'src/compiler/expression/ftnode_visitor.cpp'
--- src/compiler/expression/ftnode_visitor.cpp 2013-02-07 17:24:36 +0000
+++ src/compiler/expression/ftnode_visitor.cpp 2013-06-03 23:16:28 +0000
@@ -15,7 +15,7 @@
*/
#include "stdafx.h"
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
#include "expr_visitor.h"
#include "ftnode.h"
=== modified file 'src/compiler/parser/ft_types.cpp'
--- src/compiler/parser/ft_types.cpp 2013-02-07 17:24:36 +0000
+++ src/compiler/parser/ft_types.cpp 2013-06-03 23:16:28 +0000
@@ -15,7 +15,7 @@
*/
#include "stdafx.h"
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
#include "ft_types.h"
=== modified file 'src/context/default_uri_mappers.cpp'
--- src/context/default_uri_mappers.cpp 2013-02-07 17:24:36 +0000
+++ src/context/default_uri_mappers.cpp 2013-06-03 23:16:28 +0000
@@ -180,7 +180,7 @@
// If module-path entry is relative, normalize it against the
// static context's base URI.
if (!fs::is_absolute(*lIter)) {
- zstring lAbsPath = fs::get_normalized_path(*lIter, aSctx.get_base_uri());
+ zstring lAbsPath = fs::normalize_path(*lIter, aSctx.get_base_uri());
lCandidateURI.append(lAbsPath);
}
else {
=== modified file 'src/context/default_url_resolvers.cpp'
--- src/context/default_url_resolvers.cpp 2013-02-07 17:24:36 +0000
+++ src/context/default_url_resolvers.cpp 2013-06-03 23:16:28 +0000
@@ -15,9 +15,9 @@
*/
#include "stdafx.h"
+#include <zorba/internal/cxx_util.h>
#include "context/default_url_resolvers.h"
-#include "util/cxx_util.h"
#include "util/uri_util.h"
#include "util/http_util.h"
#include "util/fs_util.h"
@@ -125,13 +125,18 @@
if (lScheme != uri::file) {
return NULL;
}
- zstring lPath = fs::get_normalized_path(aUrl);
- if (fs::get_type(lPath) == fs::file) {
- std::ifstream* lStream = new std::ifstream(lPath.c_str());
- return new StreamResource(
- lStream, &fileStreamReleaser, "", true /* seekable */);
- }
- return NULL;
+ try {
+ std::string lPath( fs::normalize_path(aUrl) );
+ if (fs::get_type(lPath) == fs::file) {
+ std::ifstream* lStream = new std::ifstream(lPath.c_str());
+ return new StreamResource(
+ lStream, &fileStreamReleaser, "", true /* seekable */);
+ }
+ return NULL;
+ }
+ catch ( std::invalid_argument const &e ) {
+ throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
+ }
}
/******
=== modified file 'src/context/dynamic_loader.cpp'
--- src/context/dynamic_loader.cpp 2013-02-07 17:24:36 +0000
+++ src/context/dynamic_loader.cpp 2013-06-03 23:16:28 +0000
@@ -28,14 +28,15 @@
#ifdef WIN32
# include <strsafe.h>
#endif
-
-#include <diagnostics/xquery_diagnostics.h>
-#include <zorbatypes/URI.h>
+#include <fstream>
+
+#include "diagnostics/xquery_diagnostics.h"
+#include "zorbatypes/URI.h"
+
#include <zorba/external_module.h>
#include <zorba/zorba_string.h>
#include <context/get_current_lib_suffix.h>
-#include <fstream>
-#include <util/error_util.h>
+#include <zorba/util/error_util.h>
namespace zorba {
=== modified file 'src/diagnostics/assert.h'
--- src/diagnostics/assert.h 2013-02-07 17:24:36 +0000
+++ src/diagnostics/assert.h 2013-06-03 23:16:28 +0000
@@ -22,7 +22,7 @@
#include <sstream>
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
namespace zorba {
=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml 2013-05-24 22:52:47 +0000
+++ src/diagnostics/diagnostic_en.xml 2013-06-03 23:16:28 +0000
@@ -4061,10 +4061,6 @@
<value>promotion not possible</value>
</entry>
- <entry key="QuotedColon_23">
- <value>"$2": $3</value>
- </entry>
-
<entry key="SEPM0009_Not10">
<value>the version parameter has a value other than "1.0" and the doctype-system parameter is specified</value>
</entry>
=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp 2013-05-24 22:52:47 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp 2013-06-03 23:16:28 +0000
@@ -791,7 +791,6 @@
{ "~ParseFragmentInvalidOptions", "invalid options passed to the parse-xml:parse() function, the element must be in the schema target namespace" },
{ "~ParseFragmentOptionCombinationNotAllowed", "only one of the <schema-validate/>, <DTD-validate/> or <parse-external-parsed-entity/> options can be specified" },
{ "~PromotionImpossible", "promotion not possible" },
- { "~QuotedColon_23", "\"$2\": $3" },
#if defined(ZORBA_NO_ICU)
{ "~REGEX_BROKEN_PIs_CONSTRUCT", "broken \\\\p{Is} construct; valid characters are [a-zA-Z0-9-]" },
#endif
=== modified file 'src/diagnostics/pregenerated/dict_zed_keys.h'
--- src/diagnostics/pregenerated/dict_zed_keys.h 2013-05-16 22:26:07 +0000
+++ src/diagnostics/pregenerated/dict_zed_keys.h 2013-06-03 23:16:28 +0000
@@ -319,7 +319,6 @@
#define ZED_XMLParserInitFailed "~XMLParserInitFailed"
#define ZED_XMLParserNoCreateTree "~XMLParserNoCreateTree"
#define ZED_PromotionImpossible "~PromotionImpossible"
-#define ZED_QuotedColon_23 "~QuotedColon_23"
#define ZED_SEPM0009_Not10 "~SEPM0009_Not10"
#define ZED_SEPM0009_NotOmit "~SEPM0009_NotOmit"
#define ZED_SchemaUnexpected "~SchemaUnexpected"
=== modified file 'src/diagnostics/user_exception.h'
--- src/diagnostics/user_exception.h 2013-02-07 17:24:36 +0000
+++ src/diagnostics/user_exception.h 2013-06-03 23:16:28 +0000
@@ -18,13 +18,13 @@
#ifndef ZORBA_USER_EXCEPTION_H
#define ZORBA_USER_EXCEPTION_H
+#include <zorba/internal/cxx_util.h>
#include <zorba/item.h>
#include <zorba/user_exception.h>
#include "api/unmarshaller.h"
#include "compiler/parser/query_loc.h"
#include "store/api/item.h"
-#include "util/cxx_util.h"
#include "util/stl_util.h"
namespace zorba {
=== modified file 'src/diagnostics/xquery_diagnostics.h'
--- src/diagnostics/xquery_diagnostics.h 2013-02-07 17:24:36 +0000
+++ src/diagnostics/xquery_diagnostics.h 2013-06-03 23:16:28 +0000
@@ -22,12 +22,11 @@
#include <zorba/config.h>
#include <zorba/internal/unique_ptr.h>
+#include <zorba/util/error_util.h>
// TODO: this #include is temporary
#include <zorba/diagnostic_list.h>
-#include "util/error_util.h"
-
#include "diagnostic.h"
#include "dict.h"
#include "xquery_exception.h"
=== modified file 'src/diagnostics/xquery_exception.cpp'
--- src/diagnostics/xquery_exception.cpp 2013-05-24 00:27:45 +0000
+++ src/diagnostics/xquery_exception.cpp 2013-06-03 23:16:28 +0000
@@ -279,7 +279,7 @@
case uri::file:
try {
o << (as_xml ? " uri=\"" : "<")
- << fs::get_normalized_path( uri )
+ << fs::normalize_path( uri )
<< (as_xml ? '"' : '>');
break;
}
=== modified file 'src/precompiled/stdafx.h'
--- src/precompiled/stdafx.h 2013-04-17 18:37:33 +0000
+++ src/precompiled/stdafx.h 2013-06-03 23:16:28 +0000
@@ -31,6 +31,7 @@
#include <set>
#include <sys/timeb.h>
+ #include <zorba/internal/cxx_util.h>
#include "runtime/sequences/sequences.h"
#include "diagnostics/xquery_diagnostics.h"
#include "xercesc/util/xercesdefs.hpp"
@@ -48,7 +49,6 @@
#include <zorba/store_manager.h>
#include <zorba/xquery.h>
#include <zorba/xquery_exception.h>
- #include "util/cxx_util.h"
#include "diagnostics/assert.h"
#include "zorbatypes/mapm/m_apm_lc.h"
#include "zorbatypes/datetime/parse.h"
=== modified file 'src/runtime/full_text/apply.cpp'
--- src/runtime/full_text/apply.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/apply.cpp 2013-06-03 23:16:28 +0000
@@ -19,17 +19,17 @@
#include <set>
#include <vector>
+#include <zorba/internal/cxx_util.h>
#include <zorba/tokenizer.h>
-#include <context/uri_resolver.h>
#include "compiler/expression/ftnode.h"
+#include "context/uri_resolver.h"
#include "diagnostics/dict.h"
#include "diagnostics/xquery_diagnostics.h"
#include "store/api/item.h"
#include "store/api/item_factory.h"
#include "store/api/store.h"
#include "system/globalenv.h"
-#include "util/cxx_util.h"
#include "util/indent.h"
#include "util/stl_util.h"
#include "zorbamisc/ns_consts.h"
=== modified file 'src/runtime/full_text/ft_module_util.h'
--- src/runtime/full_text/ft_module_util.h 2012-06-24 14:44:40 +0000
+++ src/runtime/full_text/ft_module_util.h 2013-06-03 23:16:28 +0000
@@ -23,12 +23,12 @@
// needs to be #include'd into the .cpp generated from the ft_module.xml file.
//
+#include <deque>
+
+#include <zorba/internal/cxx_util.h>
#include <zorba/tokenizer.h>
-#include <deque>
-
#include "store/api/item.h"
-#include "util/cxx_util.h"
#include "zorbatypes/ft_token.h"
#include "ft_module_util.h"
=== modified file 'src/runtime/full_text/ft_query_item.cpp'
--- src/runtime/full_text/ft_query_item.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/ft_query_item.cpp 2013-06-03 23:16:28 +0000
@@ -15,7 +15,8 @@
*/
#include "stdafx.h"
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "util/stl_util.h"
#include "diagnostics/assert.h"
=== modified file 'src/runtime/full_text/ft_stop_words_set.cpp'
--- src/runtime/full_text/ft_stop_words_set.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/ft_stop_words_set.cpp 2013-06-03 23:16:28 +0000
@@ -16,11 +16,11 @@
#include "stdafx.h"
#include <zorba/config.h>
+#include <zorba/internal/cxx_util.h>
#include "context/static_context.h"
#include "context/uri_resolver.h"
#include "util/ascii_util.h"
-#include "util/cxx_util.h"
#include "util/mmap_file.h"
#include "util/stl_util.h"
#include "util/uri_util.h"
=== modified file 'src/runtime/full_text/ft_token_matcher.cpp'
--- src/runtime/full_text/ft_token_matcher.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/ft_token_matcher.cpp 2013-06-03 23:16:28 +0000
@@ -17,14 +17,14 @@
#include <cctype>
+#include <zorba/internal/cxx_util.h>
+
#include "compiler/expression/ftnode.h"
#include "diagnostics/assert.h"
#include "store/api/store.h"
-#include "util/cxx_util.h"
+#include "system/globalenv.h"
#include "util/stl_util.h"
-#include "system/globalenv.h"
-
#include "ft_stop_words_set.h"
#include "ft_token_matcher.h"
#include "ft_util.h"
=== modified file 'src/runtime/full_text/ft_token_seq_iterator.cpp'
--- src/runtime/full_text/ft_token_seq_iterator.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/ft_token_seq_iterator.cpp 2013-06-03 23:16:28 +0000
@@ -15,7 +15,8 @@
*/
#include "stdafx.h"
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "diagnostics/assert.h"
#include "ft_token_seq_iterator.h"
=== modified file 'src/runtime/full_text/ft_util.h'
--- src/runtime/full_text/ft_util.h 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/ft_util.h 2013-06-03 23:16:28 +0000
@@ -17,12 +17,12 @@
#ifndef ZORBA_FULL_TEXT_UTIL_H
#define ZORBA_FULL_TEXT_UTIL_H
+#include <zorba/internal/cxx_util.h>
#include <zorba/item.h>
#include <zorba/locale.h>
#include "compiler/expression/ftnode.h"
#include "store/api/item.h"
-#include "util/cxx_util.h"
#include "zorbatypes/schema_types.h"
#include "ft_match.h"
=== modified file 'src/runtime/full_text/ftcontains_visitor.cpp'
--- src/runtime/full_text/ftcontains_visitor.cpp 2013-05-08 20:14:47 +0000
+++ src/runtime/full_text/ftcontains_visitor.cpp 2013-06-03 23:16:28 +0000
@@ -19,13 +19,14 @@
#include <limits>
#include <memory>
+#include <zorba/internal/cxx_util.h>
+
#include "compiler/expression/ft_expr.h"
#include "compiler/expression/ftnode.h"
#include "compiler/parser/query_loc.h"
#include "diagnostics/xquery_diagnostics.h"
#include "store/api/store.h"
#include "system/globalenv.h"
-#include "util/cxx_util.h"
#include "util/indent.h"
#include "util/stl_util.h"
#include "zorbatypes/integer.h"
=== modified file 'src/runtime/full_text/icu_tokenizer.cpp'
--- src/runtime/full_text/icu_tokenizer.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/icu_tokenizer.cpp 2013-06-03 23:16:28 +0000
@@ -25,6 +25,7 @@
#endif /* DEBUG_TOKENIZER */
#include <zorba/diagnostic_list.h>
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/unique_ptr.h>
#include "diagnostics/assert.h"
@@ -32,7 +33,6 @@
#include "diagnostics/xquery_exception.h"
#include "diagnostics/zorba_exception.h"
#include "util/ascii_util.h"
-#include "util/cxx_util.h"
#include "util/stl_util.h"
#include "util/unicode_util.h"
#include "util/utf8_util.h"
=== modified file 'src/runtime/full_text/icu_tokenizer.h'
--- src/runtime/full_text/icu_tokenizer.h 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/icu_tokenizer.h 2013-06-03 23:16:28 +0000
@@ -19,12 +19,11 @@
#include <unicode/rbbi.h> /* for RuleBasedBreakIterator */
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/unique_ptr.h>
#include <zorba/locale.h>
#include <zorba/tokenizer.h>
-#include "util/cxx_util.h"
-
namespace zorba {
///////////////////////////////////////////////////////////////////////////////
=== modified file 'src/runtime/full_text/stemmer.cpp'
--- src/runtime/full_text/stemmer.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/stemmer.cpp 2013-06-03 23:16:28 +0000
@@ -15,7 +15,8 @@
*/
#include "stdafx.h"
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "zorbautils/locale.h"
#include "zorbautils/mutex.h"
=== modified file 'src/runtime/full_text/stemmer/sb_stemmer.cpp'
--- src/runtime/full_text/stemmer/sb_stemmer.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/stemmer/sb_stemmer.cpp 2013-06-03 23:16:28 +0000
@@ -15,7 +15,8 @@
*/
#include "stdafx.h"
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "zorbautils/fatal.h"
#include "zorbautils/locale.h"
=== modified file 'src/runtime/full_text/thesauri/encoded_list.h'
--- src/runtime/full_text/thesauri/encoded_list.h 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/thesauri/encoded_list.h 2013-06-03 23:16:28 +0000
@@ -20,7 +20,7 @@
#include <cstddef> /* for size_t */
#include <iterator>
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
namespace zorba {
=== modified file 'src/runtime/full_text/thesauri/wn_thesaurus.cpp'
--- src/runtime/full_text/thesauri/wn_thesaurus.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/thesauri/wn_thesaurus.cpp 2013-06-03 23:16:28 +0000
@@ -21,24 +21,21 @@
#include <cstring> /* for strcmp(3) */
#include <limits>
-#include <zorba/util/path.h>
-
-#include <context/static_context.h>
-
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
+#include "context/static_context.h"
+#include "diagnostics/assert.h"
+#include "diagnostics/dict.h"
+#include "diagnostics/xquery_diagnostics.h"
+#include "system/globalenv.h"
#include "util/fs_util.h"
#include "util/less.h"
#if DEBUG_FT_THESAURUS
-#include "util/oseparator.h"
+# include "util/oseparator.h"
#endif
#include "util/utf8_util.h"
-#include "diagnostics/assert.h"
-#include "diagnostics/dict.h"
-#include "diagnostics/xquery_diagnostics.h"
#include "zorbautils/locale.h"
-#include "system/globalenv.h"
-
#include "decode_base128.h"
#include "wn_db_segment.h"
#include "wn_synset.h"
=== modified file 'src/runtime/full_text/thesaurus.cpp'
--- src/runtime/full_text/thesaurus.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/full_text/thesaurus.cpp 2013-06-03 23:16:28 +0000
@@ -18,15 +18,16 @@
#include <map>
#include <zorba/config.h>
+#include <zorba/internal/cxx_util.h>
-#include <context/static_context.h>
-#include <diagnostics/dict.h>
-#include <diagnostics/xquery_diagnostics.h>
-#include <util/cxx_util.h>
-#include <util/fs_util.h>
-#include <util/less.h>
-#include <util/string_util.h>
-#include <util/uri_util.h>
+#include "context/default_url_resolvers.h"
+#include "context/static_context.h"
+#include "diagnostics/dict.h"
+#include "diagnostics/xquery_diagnostics.h"
+#include "util/fs_util.h"
+#include "util/less.h"
+#include "util/string_util.h"
+#include "util/uri_util.h"
#include "thesaurus.h"
#ifdef ZORBA_WITH_FILE_ACCESS
@@ -35,8 +36,6 @@
#endif
#include "thesauri/xqftts_thesaurus.h"
-#include "context/default_url_resolvers.h"
-
using namespace std;
using namespace zorba::locale;
@@ -112,8 +111,13 @@
//
zstring t_uri( url_copy );
t_uri.replace( 0, 6, "file" ); // xqftts -> file
- zstring const t_path( fs::get_normalized_path( t_uri ) );
- return new xqftts::provider( t_path );
+ try {
+ zstring const t_path( fs::normalize_path( t_uri ) );
+ return new xqftts::provider( t_path );
+ }
+ catch ( invalid_argument const &e ) {
+ throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
+ }
}
# endif /* ZORBA_WITH_FILE_ACCESS */
case thesaurus_impl::wordnet:
=== modified file 'src/runtime/json/json_impl.cpp'
--- src/runtime/json/json_impl.cpp 2013-02-26 04:12:43 +0000
+++ src/runtime/json/json_impl.cpp 2013-06-03 23:16:28 +0000
@@ -19,13 +19,12 @@
#include <sstream>
#include <zorba/diagnostic_list.h>
+#include <zorba/internal/cxx_util.h>
#include "runtime/json/json.h"
#include "store/api/item_factory.h"
#include "system/globalenv.h"
-
#include "util/ascii_util.h"
-#include "util/cxx_util.h"
#include "util/mem_streambuf.h"
#include "util/stream_util.h"
=== modified file 'src/runtime/json/jsonml_array.cpp'
--- src/runtime/json/jsonml_array.cpp 2013-04-02 02:48:56 +0000
+++ src/runtime/json/jsonml_array.cpp 2013-06-03 23:16:28 +0000
@@ -18,13 +18,13 @@
#include <sstream>
#include <zorba/diagnostic_list.h>
+#include <zorba/internal/cxx_util.h>
#include "runtime/json/json.h"
#include "store/api/item_factory.h"
#include "system/globalenv.h"
#include "types/root_typemanager.h"
#include "util/ascii_util.h"
-#include "util/cxx_util.h"
#include "util/json_parser.h"
#include "util/json_util.h"
#include "util/mem_streambuf.h"
=== modified file 'src/runtime/json/snelson.cpp'
--- src/runtime/json/snelson.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/json/snelson.cpp 2013-06-03 23:16:28 +0000
@@ -19,13 +19,13 @@
#include <string>
#include <zorba/diagnostic_list.h>
+#include <zorba/internal/cxx_util.h>
#include "runtime/json/json.h"
#include "store/api/item_factory.h"
#include "system/globalenv.h"
#include "types/root_typemanager.h"
#include "util/ascii_util.h"
-#include "util/cxx_util.h"
#include "util/indent.h"
#include "util/json_parser.h"
#include "util/json_util.h"
=== modified file 'src/runtime/util/doc_uri_heuristics.cpp'
--- src/runtime/util/doc_uri_heuristics.cpp 2012-10-16 14:30:02 +0000
+++ src/runtime/util/doc_uri_heuristics.cpp 2013-06-03 23:16:28 +0000
@@ -47,24 +47,31 @@
uri::get_scheme(aUri) == uri::unknown) &&
uri::get_scheme(lBaseUri) == uri::file)
{
- // Ok, we assume it's a filesystem path. First normalize it.
- zstring lNormalizedPath = fs::get_normalized_path(
- aUri,
- zstring(""));
- // QQQ For now, get_normalized_path() doesn't do what we
- // want when base URI represents a file. So, when the
- // normalized path is relative, we pretend it's a relative
- // URI and resolve it as such.
- if (fs::is_absolute(lNormalizedPath))
+ try
{
- URI::encode_file_URI(lNormalizedPath, *aResult);
+ // Ok, we assume it's a filesystem path. First normalize it.
+ zstring lNormalizedPath = fs::normalize_path(
+ aUri,
+ zstring(""));
+ // QQQ For now, normalize_path() doesn't do what we
+ // want when base URI represents a file. So, when the
+ // normalized path is relative, we pretend it's a relative
+ // URI and resolve it as such.
+ if (fs::is_absolute(lNormalizedPath))
+ {
+ URI::encode_file_URI(lNormalizedPath, *aResult);
+ }
+ else
+ {
+ #ifdef WIN32
+ ascii::replace_all(lNormalizedPath, '\\', '/');
+ #endif
+ *aResult = aSctx->resolve_relative_uri(lNormalizedPath, true);
+ }
}
- else
+ catch ( std::invalid_argument const &e )
{
-#ifdef WIN32
- ascii::replace_all(lNormalizedPath, '\\', '/');
-#endif
- *aResult = aSctx->resolve_relative_uri(lNormalizedPath, true);
+ throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
}
}
else
@@ -87,6 +94,5 @@
}
}
-} /* namespace zorba */
+} // namespace zorba
/* vim:set et sw=2 ts=2: */
-
=== modified file 'src/store/naive/ft_token_store.h'
--- src/store/naive/ft_token_store.h 2013-02-07 17:24:36 +0000
+++ src/store/naive/ft_token_store.h 2013-06-03 23:16:28 +0000
@@ -21,7 +21,8 @@
#include <utility> /* for pair */
#include <vector>
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "zorbatypes/ft_token.h"
namespace zorba {
=== modified file 'src/store/naive/naive_ft_token_iterator.cpp'
--- src/store/naive/naive_ft_token_iterator.cpp 2013-02-07 17:24:36 +0000
+++ src/store/naive/naive_ft_token_iterator.cpp 2013-06-03 23:16:28 +0000
@@ -15,8 +15,9 @@
*/
#include "stdafx.h"
+#include <zorba/internal/cxx_util.h>
+
#include "diagnostics/assert.h"
-#include "util/cxx_util.h"
#include "naive_ft_token_iterator.h"
=== modified file 'src/store/naive/store.cpp'
--- src/store/naive/store.cpp 2013-03-20 18:39:54 +0000
+++ src/store/naive/store.cpp 2013-06-03 23:16:28 +0000
@@ -21,6 +21,8 @@
#include <libxml/parser.h>
+#include <zorba/internal/cxx_util.h>
+
#include "zorbautils/hashfun.h"
#include "zorbautils/fatal.h"
#include "zorbatypes/rchandle.h"
@@ -57,7 +59,6 @@
#include "pul_primitive_factory.h"
#include "tree_id_generator.h"
-#include "util/cxx_util.h"
#include "zorbautils/string_util.h"
#ifndef ZORBA_NO_FULL_TEXT
=== modified file 'src/unit_tests/CMakeLists.txt'
--- src/unit_tests/CMakeLists.txt 2013-04-16 18:24:35 +0000
+++ src/unit_tests/CMakeLists.txt 2013-06-03 23:16:28 +0000
@@ -17,6 +17,7 @@
test_ato_.cpp
test_base64.cpp
test_base64_streambuf.cpp
+ test_fs_util.cpp
test_hashmaps.cpp
test_hexbinary.cpp
test_json_parser.cpp
@@ -26,16 +27,11 @@
test_time.cpp
test_time_parse.cpp
test_uri.cpp
+ test_utf8_streambuf.cpp
test_uuid.cpp
unit_tests.cpp
- test_utf8_streambuf.cpp
)
-IF (ZORBA_WITH_FILE_ACCESS)
- LIST (APPEND UNIT_TEST_SRCS
- test_fs_iterator.cpp)
-ENDIF (ZORBA_WITH_FILE_ACCESS)
-
IF (NOT ZORBA_NO_FULL_TEXT)
LIST (APPEND UNIT_TEST_SRCS
test_stemmer.cpp
=== modified file 'src/unit_tests/test_ato_.cpp'
--- src/unit_tests/test_ato_.cpp 2013-05-03 23:19:41 +0000
+++ src/unit_tests/test_ato_.cpp 2013-06-03 23:16:28 +0000
@@ -19,7 +19,8 @@
#include <stdexcept>
#include <string>
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "util/string_util.h"
using namespace std;
=== removed file 'src/unit_tests/test_fs_iterator.cpp'
--- src/unit_tests/test_fs_iterator.cpp 2012-04-22 15:49:55 +0000
+++ src/unit_tests/test_fs_iterator.cpp 1970-01-01 00:00:00 +0000
@@ -1,54 +0,0 @@
-/*
- * Copyright 2006-2010 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "stdafx.h"
-
-#include <iostream>
-#include <zorba/zorba_exception.h>
-
-#include "util/fs_util.h"
-
-using namespace std;
-using namespace zorba;
-
-///////////////////////////////////////////////////////////////////////////////
-
-namespace zorba {
-namespace UnitTests {
-
-int test_fs_iterator( int argc, char *argv[] ) {
- int result = 0;
- try {
-#ifndef WIN32
- fs::iterator dir_iter( "/" );
-#else
- fs::iterator dir_iter( "C:\\" );
-#endif /* WIN32 */
- while ( dir_iter.next() )
- cout << dir_iter.entry_name() << " (" << dir_iter.entry_type() << ')' << endl;
- }
- catch ( ZorbaException const &e ) {
- cerr << e << endl;
- result = 2;
- }
-
- return result;
-}
-
-} // namespace UnitTests
-} // namespace zorba
-
-/* vim:set et sw=2 ts=2: */
=== added file 'src/unit_tests/test_fs_util.cpp'
--- src/unit_tests/test_fs_util.cpp 1970-01-01 00:00:00 +0000
+++ src/unit_tests/test_fs_util.cpp 2013-06-03 23:16:28 +0000
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "stdafx.h"
+
+#include <cstring>
+
+#include "util/fs_util.h"
+
+using namespace std;
+using namespace zorba;
+
+struct test {
+ char const *input;
+ char const *expected;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+static int failures;
+
+static bool assert_true( int no, char const *expr, int line, bool result ) {
+ if ( !result ) {
+ cout << '#' << no << " FAILED, line " << line << ": " << expr << endl;
+ ++failures;
+ }
+ return result;
+}
+
+static void print_exception( int no, char const *expr, int line,
+ std::exception const &e ) {
+ assert_true( no, expr, line, false );
+ cout << "+ exception: " << e.what() << endl;
+}
+
+#define ASSERT_TRUE( NO, EXPR ) assert_true( NO, #EXPR, __LINE__, !!(EXPR) )
+
+#define ASSERT_NO_EXCEPTION( NO, EXPR ) \
+ try { EXPR; } \
+ catch ( exception const &e ) { print_exception( NO, #EXPR, __LINE__, e ); } \
+ catch ( ... ) { assert_true( NO, #EXPR, __LINE__, false ); }
+
+#define ASSERT_EXCEPTION( NO, EXPR, EXCEPTION ) \
+ try { EXPR; assert_true( NO, #EXPR, __LINE__, false ); } \
+ catch ( EXCEPTION const& ) { } \
+ catch ( ... ) { assert_true( NO, #EXPR, __LINE__, false ); }
+
+///////////////////////////////////////////////////////////////////////////////}
+
+void test_base_name( int no, char const *path, char const *expected ) {
+ ASSERT_TRUE( no, ::strcmp( fs::base_name( path ), expected ) == 0 );
+}
+
+void test_base_name( int no, string const &path, string const &expected ) {
+ ASSERT_TRUE( no, fs::base_name( path ) == expected );
+}
+
+void test_dir_name( int no, char const *path, char const *expected ) {
+ ASSERT_TRUE( no, fs::dir_name( path ) == expected );
+}
+
+void test_dir_name( int no, string const &path, string const &expected ) {
+ ASSERT_TRUE( no, fs::dir_name( path ) == expected );
+}
+
+void test_normalize_path( int no, char const *path, char const *expected ) {
+ ASSERT_TRUE( no, fs::normalize_path( path ) == expected );
+}
+
+///////////////////////////////////////////////////////////////////////////////}
+
+static test const base_name_tests[] = {
+#ifndef WIN32
+ /* 0 */ { "/a/b", "b" },
+ /* 1 */ { "/a" , "a" },
+ /* 2 */ { "/" , "/" },
+ /* 3 */ { "a/b" , "b" },
+ /* 4 */ { "a" , "a" },
+#else
+ /* 0 */ { "C:\\a\\b", "b" },
+ /* 1 */ { "C:\\a" , "a" },
+ /* 2 */ { "C:\\" , "C:\\" },
+ /* 3 */ { "a\\b" , "b" },
+ /* 4 */ { "a" , "a" },
+#endif /* WIN32 */
+ { 0, 0 }
+};
+
+static test const dir_name_tests[] = {
+#ifndef WIN32
+ /* 0 */ { "/a/b", "/a" },
+ /* 1 */ { "/a" , "/" },
+ /* 2 */ { "/" , "/" },
+ /* 3 */ { "a/b" , "a" },
+ /* 4 */ { "a" , "." },
+#else
+ /* 0 */ { "C:\\a\\b", "C:\\a" },
+ /* 1 */ { "C:\\a" , "C:\\" },
+ /* 2 */ { "C"\\" , "C:\\" },
+ /* 3 */ { "a\\b" , "a" },
+ /* 4 */ { "a" , "." },
+#endif /* WIN32 */
+ { 0, 0 }
+};
+
+static test normalize_path_tests[] = {
+#ifndef WIN32
+ /* 0 */ { "/a//b" , "/a/b" },
+ /* 1 */ { "/a///b" , "/a/b" },
+ /* 2 */ { "/a/./b" , "/a/b" },
+ /* 3 */ { "/a/././b" , "/a/b" },
+ /* 4 */ { "/a/b/." , "/a/b" },
+ /* 5 */ { "/a/../b" , "/b" },
+ /* 6 */ { "/a/b/../../c" , "/c" },
+ /* 7 */ { "/a/b/../c/../d" , "/a/d" },
+ /* 8 */ { "/a/b/.." , "/a" },
+ /* 9 */ { "file:///a/b" , "/a/b" },
+ /* 10 */ { "file://localhost/a/b" , "/a/b" },
+ /* 11 */ { "\\a\\b" , "/a/b" },
+#else
+ /* 0 */ { "C:\\a\\\\b" , "C:\\a\\b" },
+ /* 1 */ { "C:\\a\\\\\\b" , "C:\\a\\b" },
+ /* 2 */ { "C:\\a\\.\\b" , "C:\\a\\b" },
+ /* 3 */ { "C:\\a\\.\\.\\b" , "C:\\a\\b" },
+ /* 4 */ { "C:\\a\\b\\." , "C:\\a\\b" },
+ /* 5 */ { "C:\\a\\..\\b" , "C:\\b" },
+ /* 6 */ { "C:\\a\\b\\..\\..\\c" , "C:\\c" },
+ /* 7 */ { "C:\\a\\b\\..\\c\\..\\d" , "C:\\a\\d" },
+ /* 8 */ { "C:\\a\\b\\.." , "C:\\a" },
+ /* 9 */ { "file:///C%3A/a/b" , "C:\\a\\b" },
+ /* 10 */ { "file://localhost/C%3A/a/b" , "C:\\a\\b" },
+ /* 11 */ { "C:/a/b" , "C:\\a\\b" },
+#endif /* WIN32 */
+ { 0, 0 }
+};
+
+namespace zorba {
+namespace UnitTests {
+
+int test_fs_util( int, char*[] ) {
+ int test_no = 0;
+
+ for ( test const *t = base_name_tests; t->input; ++t, ++test_no ) {
+ test_base_name( test_no, t->input, t->expected );
+ test_base_name( test_no, string( t->input ), string( t->expected ) );
+ }
+
+ test_no = 0;
+ for ( test const *t = dir_name_tests; t->input; ++t, ++test_no ) {
+ test_dir_name( test_no, t->input, t->expected );
+ test_dir_name( test_no, string( t->input ), string( t->expected ) );
+ }
+
+ test_no = 0;
+ for ( test const *t = normalize_path_tests; t->input; ++t, ++test_no )
+ test_normalize_path( test_no, t->input, t->expected );
+
+ cout << failures << " test(s) failed\n";
+ return failures ? 1 : 0;
+}
+
+} // namespace UnitTests
+} // namespace zorba
+
+/* vim:set et sw=2 ts=2: */
=== modified file 'src/unit_tests/test_mem_sizeof.cpp'
--- src/unit_tests/test_mem_sizeof.cpp 2013-04-17 18:37:33 +0000
+++ src/unit_tests/test_mem_sizeof.cpp 2013-06-03 23:16:28 +0000
@@ -18,7 +18,8 @@
#include <iostream>
#include <string>
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "util/mem_sizeof.h"
using namespace std;
=== modified file 'src/unit_tests/unit_test_list.h'
--- src/unit_tests/unit_test_list.h 2013-04-16 18:24:35 +0000
+++ src/unit_tests/unit_test_list.h 2013-06-03 23:16:28 +0000
@@ -31,6 +31,7 @@
int test_ato_( int, char*[] );
int test_base64( int, char*[] );
int test_base64_streambuf( int, char*[] );
+ int test_fs_util( int, char*[] );
int test_hashmaps( int argc, char* argv[] );
int test_hexbinary( int argc, char* argv[] );
@@ -45,10 +46,6 @@
int test_time( int, char*[] );
int test_time_parse( int, char*[] );
-#ifdef ZORBA_WITH_FILE_ACCESS
- int test_fs_iterator( int, char*[] );
-#endif /* ZORBA_WITH_FILE_ACCESS */
-
#ifndef ZORBA_NO_FULL_TEXT
int test_stemmer( int, char*[] );
int test_thesaurus( int, char*[] );
=== modified file 'src/unit_tests/unit_tests.cpp'
--- src/unit_tests/unit_tests.cpp 2013-04-16 18:24:35 +0000
+++ src/unit_tests/unit_tests.cpp 2013-06-03 23:16:28 +0000
@@ -40,11 +40,7 @@
libunittests["ato"] = test_ato_;
libunittests["base64"] = test_base64;
libunittests["base64_streambuf"] = test_base64_streambuf;
-
-#ifdef ZORBA_WITH_FILE_ACCESS
- libunittests["fs_iterator"] = test_fs_iterator;
-#endif /* ZORBA_WITH_FILE_ACCESS */
-
+ libunittests["fs_util"] = test_fs_util;
libunittests["hashmaps"] = test_hashmaps;
libunittests["hexbinary"] = test_hexbinary;
=== modified file 'src/util/CMakeLists.txt'
--- src/util/CMakeLists.txt 2013-04-12 04:34:41 +0000
+++ src/util/CMakeLists.txt 2013-06-03 23:16:28 +0000
@@ -17,7 +17,6 @@
base64_util.cpp
dynamic_bitset.cpp
error_util.cpp
- file.cpp
fs_util.cpp
hexbinary_util.cpp
indent.cpp
=== modified file 'src/util/ascii_util.tcc'
--- src/util/ascii_util.tcc 2013-05-09 00:48:27 +0000
+++ src/util/ascii_util.tcc 2013-06-03 23:16:28 +0000
@@ -85,8 +85,7 @@
char const *from, typename StringType::size_type from_len,
char const *to, typename StringType::size_type to_len ) {
bool replaced_any = false;
- for ( typename StringType::size_type pos = 0;
- pos + from_len <= s.size(); pos += to_len ) {
+ for ( typename StringType::size_type pos = 0; pos + from_len <= s.size(); ) {
if ( (pos = s.find( from, pos, from_len )) == StringType::npos )
break;
s.replace( pos, from_len, to, to_len );
=== modified file 'src/util/base64_util.h'
--- src/util/base64_util.h 2013-05-09 00:48:27 +0000
+++ src/util/base64_util.h 2013-06-03 23:16:28 +0000
@@ -25,8 +25,8 @@
#include <vector>
// Zorba
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/ztd.h>
-#include "cxx_util.h"
#include "stream_util.h"
namespace zorba {
=== modified file 'src/util/cxx_util.cpp'
--- src/util/cxx_util.cpp 2013-01-15 19:16:16 +0000
+++ src/util/cxx_util.cpp 2013-06-03 23:16:28 +0000
@@ -20,9 +20,9 @@
#ifndef ZORBA_CXX_NULLPTR
-#include "cxx_util.h"
+#include <zorba/internal/cxx_util.h>
-zorba::nullptr_type const zorba_nullptr = { };
+zorba::internal::nullptr_type const zorba_nullptr = { };
#endif /* ZORBA_CXX_NULLPTR */
=== modified file 'src/util/error_util.cpp'
--- src/util/error_util.cpp 2013-02-07 17:24:36 +0000
+++ src/util/error_util.cpp 2013-06-03 23:16:28 +0000
@@ -17,7 +17,6 @@
#include <sstream>
-# include <cstring>
#ifndef WIN32
# include <cstdio>
#else
@@ -25,11 +24,11 @@
#endif /* WIN32 */
#include <zorba/internal/unique_ptr.h>
+#include <zorba/util/error_util.h>
#include "diagnostics/dict.h"
#include "diagnostics/diagnostic.h"
-#include "error_util.h"
#include "stl_util.h"
namespace zorba {
@@ -39,12 +38,8 @@
////////// exception //////////////////////////////////////////////////////////
-exception::~exception() throw() {
- // out-of-line since it's virtual
-}
-
-string exception::make_what( char const *function, char const *path,
- char const *err_string ) {
+static string make_what( char const *function, char const *path,
+ char const *err_string ) {
ostringstream oss;
if ( path && *path )
oss << '"' << path << "\": ";
@@ -55,6 +50,17 @@
return oss.str();
}
+exception::exception( char const *function, char const *path,
+ char const *err_string ) :
+ runtime_error( make_what( function, path, err_string ) ),
+ function_( function ), path_( path )
+{
+}
+
+exception::~exception() throw() {
+ // out-of-line since it's virtual
+}
+
///////////////////////////////////////////////////////////////////////////////
string format_err_string( char const *function, char const *err_string ) {
@@ -65,9 +71,8 @@
parameters const params( ERROR_PARAMS( function, err_string ) );
params.substitute( &result );
return result;
- } else {
- return err_string;
}
+ return err_string;
}
string format_err_string( char const *function, code_type code,
@@ -91,7 +96,7 @@
string get_err_string( char const *function, code_type code ) {
#ifndef WIN32
char err_string[ 128 ];
- ::strerror_r( code, err_string, sizeof( err_string ) );
+ ::strerror_r( code, err_string, sizeof err_string );
#else
LPWSTR werr_string;
FormatMessage(
=== removed file 'src/util/file.cpp'
--- src/util/file.cpp 2013-03-06 02:54:03 +0000
+++ src/util/file.cpp 1970-01-01 00:00:00 +0000
@@ -1,337 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "stdafx.h"
-
-#include <zorba/util/file.h>
-
-#if !defined (WIN32) && !defined (APPLE) && !defined (__FreeBSD__) && !defined(_XOPEN_SOURCE)
-#define _XOPEN_SOURCE 600 // getcwd
-#endif
-
-#ifndef _WIN32_WCE
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#else
-#include <types.h>
-#endif
-#include <stdio.h>
-
-#ifdef WIN32
-#ifndef _WIN32_WCE
-#include <io.h>
-#include <direct.h>
-#else
-#include <sys/types.h>
-#endif
-#else
-#include <sys/param.h>
-#include <unistd.h>
-#endif
-
-#include <zorba/config.h>
-
-#include "ascii_util.h"
-#include "fs_util.h"
-#include "regex.h"
-#include "uri_util.h"
-#include "utf8_util.h"
-#include "diagnostics/xquery_diagnostics.h"
-#include "diagnostics/xquery_exception.h"
-
-
-using namespace std;
-namespace zorba {
-
-std::string filesystem_path::normalize_path( std::string const &aIn,
- std::string const &aBase ) {
- return fs::get_normalized_path( aIn, aBase ).str();
-}
-
-const char* filesystem_path::get_directory_separator() {
-#ifdef WIN32
- return "\\";
-#else
- return "/";
-#endif
-}
-
-const char* filesystem_path::get_path_separator() {
-#ifdef WIN32
- return ";";
-#else
- return ":";
-#endif
-}
-
-filesystem_path::filesystem_path() {
- path = fs::curdir().c_str();
-}
-
-filesystem_path::filesystem_path (const string &path_, int flags)
- : path (path_)
-{
- if ((flags & CONVERT_SLASHES) != 0)
- ascii::replace_all (path, "/", get_directory_separator ());
- canonicalize ();
- if ((flags & RESOLVE) != 0)
- resolve_relative ();
-}
-
-bool
-filesystem_path::is_complete () const
-{
-#ifdef WIN32
- // c:dir1\file is NOT absolute! Only c:\dir\file is
- if (path.size () >= 3 && isalpha (path [0]) && path [1] == ':' && path [2] == '\\')
- return true;
-#endif
- const std::string &sep = get_directory_separator ();
- if (path.compare (0, sep.size (), sep) == 0)
- return true;
- return false;
-}
-
-void
-filesystem_path::resolve_relative ()
-{
- fs::make_absolute( path );
-}
-
-bool
-filesystem_path::is_root () const
-{
- const string &sep = get_directory_separator ();
-#ifdef WIN32
- return path.size () == 3
- && isalpha (path [0]) && path [1] == ':'
- && path.compare (2, sep.size (), sep) == 0;
-#else
- return path == sep;
-#endif
-}
-
-void filesystem_path::canonicalize ()
-{
- const string &sep = get_directory_separator ();
- string::size_type pos, start;
- string pfx;
- bool last_seg;
- bool initial_dotdots = false, next_initial_dotdots;
-
-#ifdef WIN32
- size_t rtsize = 2 + sep.size (); // length of 'C:\'
- if (path.size () > rtsize && filesystem_path (path.substr (0, rtsize)).is_root ()) {
- pfx = path.substr (0, 2);
- path = path.substr (2);
- }
-#endif
- for (pos = start = 0, last_seg = false;
- ! last_seg && pos != path.size ();
- pos += sep.size (), start = pos, initial_dotdots = next_initial_dotdots)
- {
- next_initial_dotdots = false;
- pos = path.find (sep, pos);
- if (pos == string::npos) {
- pos = path.size ();
- last_seg = true;
- }
- // cout << "path: " << path << " start: " << start << " pos: " << pos << endl;
- string seg = path.substr (start, pos - start);
- if ((seg.empty () && start != 0) || seg == ".") {
- path.erase (start, pos - start + sep.size ());
- pos = start - sep.size ();
- } else if (seg == "..") {
- string::size_type prev;
- if (start == 0 || initial_dotdots) {
- // cout << "initial or continued ..\n";
- next_initial_dotdots = true;
- continue; // initial ..
- }
- if (start == sep.size ()) {
- // cout << "initial /..\n";
- prev = sep.size ();
- } else {
- prev = path.rfind (sep, start - sep.size () - 1);
- // cout << "prev @" << (int) (prev == string::npos ? -1 : prev) << endl;
- if (prev == string::npos)
- prev = 0;
- else
- prev += sep.size ();
- }
-#ifdef WIN32
- if(0 == prev)
- path = path.substr(0, rtsize);
- else
- path.erase (prev, pos - prev + sep.size ());
-#else
- path.erase (prev, pos - prev + sep.size ());
-#endif
- pos = prev - sep.size ();
- }
- }
- if (! pfx.empty ())
- path = pfx + path;
- if (path.empty ())
- path = ".";
- else if (path.size () != sep.size () && path.compare (path.size () - sep.size (), sep.size (), sep) == 0)
- path.erase (path.size () - sep.size (), sep.size ());
-}
-
-filesystem_path
-filesystem_path::branch_path () const
-{
- if (is_root () && is_complete ())
- return *this;
-
- const string &sep = get_directory_separator ();
- string::size_type pos = path.rfind (sep);
- if (pos == string::npos) {
- return filesystem_path (".");
- } else if (pos + sep.size () == path.size ()) {
- // Final separator -- eliminate.
- // Shouldn't happen, canonicalize() does this too
- filesystem_path other = path.substr (0, pos);
- return other.branch_path ();
- }
- else return filesystem_path (path.substr (0, pos + sep.size ()));
-}
-
-std::string filesystem_path::getPathString() const {
- return path;
-}
-
-file::filetype file::do_stat( bool follow_symlinks, file_size_t *size ) const {
-#ifdef ZORBA_WITH_FILE_ACCESS
- fs::size_type fs_size = 0;
- filetype ft;
- switch ( fs::get_type( get_path(), follow_symlinks, &fs_size ) ) {
- case fs::non_existent: ft = type_non_existent; break;
- case fs::directory : ft = type_directory; break;
- case fs::file : ft = type_file; break;
- case fs::link : ft = type_link; break;
- case fs::volume : ft = type_volume; break;
- case fs::other : ft = type_other; break;
- }
- if ( size )
- *size = static_cast<file_size_t>( fs_size );
- return ft;
-#else
- if ( size )
- *size = 0;
- return type_non_existent;
-#endif
-}
-
-file::file( const filesystem_path &path_, int flags_ ) :
- filesystem_path( path_, flags_ )
-{
-}
-
-time_t file::lastModified() const {
-#ifdef ZORBA_WITH_FILE_ACCESS
- struct stat s;
- if ( ::stat( get_path().c_str(), &s ) == 0 )
- return s.st_mtime;
-#endif
- return -1;
-}
-
-void file::create() {
-#ifdef ZORBA_WITH_FILE_ACCESS
- try {
- fs::create( get_path() );
- }
- catch ( fs::exception const &e ) {
- throw ZORBA_IO_EXCEPTION( e.function(), e.path() );
- }
-#endif
-}
-
-void file::mkdir() {
-#ifdef ZORBA_WITH_FILE_ACCESS
- try {
- fs::mkdir( get_path() );
- }
- catch ( fs::exception const &e ) {
- throw ZORBA_IO_EXCEPTION( e.function(), e.path() );
- }
-#endif
-}
-
-void file::lsdir(std::vector<std::string> &list) {
-#ifdef ZORBA_WITH_FILE_ACCESS
- try {
- fs::iterator dir_iter( get_path() );
- while ( dir_iter.next() )
- list.push_back( dir_iter.entry_name() );
- }
- catch ( fs::exception const &e ) {
- throw ZORBA_IO_EXCEPTION( e.function(), e.path() );
- }
-#endif
-}
-
-void file::deep_mkdir() {
-#ifdef ZORBA_WITH_FILE_ACCESS
- vector<file> files;
- for ( file f = *this; !f.exists(); f = f.branch_path() )
- files.push_back( f );
- for ( int i = files.size() - 1; i >= 0; --i )
- files[i].mkdir();
-#endif
-}
-
-void file::remove( bool ignore ) {
-#ifdef ZORBA_WITH_FILE_ACCESS
- if ( !fs::remove( get_path() ) && !ignore )
- throw ZORBA_IO_EXCEPTION( "remove()", get_path() );
-#endif
-}
-
-void file::rmdir( bool ignore ) {
- remove( ignore );
-}
-
-#ifdef ZORBA_WITH_FILE_ACCESS
-#ifndef _WIN32_WCE
-void file::chdir() {
- if ( is_directory() ) {
- try {
- fs::chdir( get_path() );
- }
- catch ( fs::exception const &e ) {
- throw ZORBA_IO_EXCEPTION( e.function(), e.path() );
- }
- }
-}
-#endif
-#endif /* ZORBA_WITH_FILE_ACCESS */
-
-void file::rename( std::string const& newpath ) {
-#ifdef ZORBA_WITH_FILE_ACCESS
- try {
- fs::rename( get_path(), newpath );
- }
- catch ( fs::exception const &e ) {
- throw ZORBA_IO_EXCEPTION( e.function(), e.path() );
- }
- set_path( newpath );
-#endif
-}
-
-} // namespace zorba
-/* vim:set et sw=2 ts=2: */
=== modified file 'src/util/fs_util.cpp'
--- src/util/fs_util.cpp 2013-03-06 01:45:25 +0000
+++ src/util/fs_util.cpp 2013-06-03 23:16:28 +0000
@@ -15,22 +15,22 @@
*/
#include "stdafx.h"
-#include <zorba/util/path.h>
-
#ifndef WIN32
+# include <climits> /* for PATH_MAX */
+# include <cstdio>
# include <fcntl.h> /* for creat(2) */
-# include <cstdio>
+# include <sys/stat.h>
# include <sys/types.h>
-# include <sys/stat.h>
# include <unistd.h> /* for chdir(2) */
#else
# include <shlwapi.h>
#endif /* WIN32 */
+#include <zorba/internal/cxx_util.h>
+
#include "diagnostics/xquery_diagnostics.h"
#include "ascii_util.h"
-#include "cxx_util.h"
#include "fs_util.h"
#include "string_util.h"
#include "uri_util.h"
@@ -53,6 +53,60 @@
////////// helper functions ///////////////////////////////////////////////////
+static void canonicalize( string *path ) {
+#ifdef WIN32
+ // Temporarily remove the drive letter and ':' to make the code simpler.
+ string drive;
+ if ( is_absolute( *path ) ) {
+ drive = path->substr( 0, 2 );
+ path->erase( 0, 2 );
+ }
+#endif /* WIN32 */
+
+ *path += dir_separator; // add sentinel
+
+ ////////// Part 1: replace // by /
+
+ char rbuf[5];
+ rbuf[0] = rbuf[1] = dir_separator;
+
+ while ( ascii::replace_all( *path, rbuf, 2, rbuf, 1 ) )
+ ;
+
+ ////////// Part 2: remove ./
+
+ // actually look for /./ so as not to interfere with ../ case
+ rbuf[0] = rbuf[2] = dir_separator;
+ rbuf[1] = '.';
+
+ ascii::replace_all( *path, rbuf, 3, rbuf, 1 );
+
+ ////////// Part 3: remove ../
+
+ rbuf[0] = rbuf[3] = dir_separator;
+ rbuf[1] = rbuf[2] = '.';
+ rbuf[4] = '\0';
+
+ for ( string::size_type pos = 0;
+ (pos = path->find( rbuf, pos )) != string::npos; ) {
+ if ( !pos ) // leading /../
+ path->erase( 0, 3 );
+ else {
+ string::size_type const prev_pos = path->rfind( dir_separator, pos - 1 );
+ if ( prev_pos != string::npos ) {
+ path->erase( prev_pos, pos - prev_pos + 3 );
+ pos = prev_pos;
+ }
+ }
+ }
+
+ if ( path->size() > 1 )
+ path->erase( path->size() - 1 ); // remove sentinel
+#ifdef WIN32
+ path->insert( 0, drive );
+#endif /* WIN32 */
+}
+
#ifndef WIN32
inline bool is_dots( char const *s ) {
return s[0] == '.' && (!s[1] || (s[1] == '.' && !s[2]));
@@ -63,7 +117,49 @@
}
#endif /* WIN32 */
-inline void replace_foreign( zstring *path ) {
+static bool parse_file_uri( char const *uri, string *result ) {
+ if ( !ascii::begins_with( uri, "file://" ) )
+ return false;
+
+ using namespace diagnostic;
+
+ *result = uri + 7;
+ if ( result->empty() )
+ throw invalid_argument( dict::lookup( ZED( EmptyPath ) ) );
+ string::size_type slash = result->find( '/' );
+ if ( slash == string::npos )
+ throw invalid_argument(
+ BUILD_STRING( '"', uri, "\": ", dict::lookup( ZED( BadPath ) ) )
+ );
+ if ( slash > 0 ) {
+ string const authority( result->substr( 0, slash ) );
+ if ( authority != "localhost" )
+ throw invalid_argument(
+ BUILD_STRING(
+ '"', authority, "\": ", dict::lookup( ZED( NonLocalhostAuthority ) )
+ )
+ );
+ }
+#ifdef WIN32
+ ++slash; // skip leading '/' in "/C:/file.txt"
+#endif /* WIN32 */
+ *result = result->substr( slash );
+ uri::decode( *result );
+#ifdef WIN32
+ replace_foreign( &result );
+ if ( !is_absolute( result ) )
+ throw invalid_argument(
+ BUILD_STRING(
+ '"', result, "\": ", dict::lookup( ZED( NoDriveSpecification ) )
+ )
+ );
+#endif /* WIN32 */
+ return true;
+}
+
+template<class PathStringType> inline
+typename std::enable_if<ZORBA_IS_STRING(PathStringType),void>::type
+replace_foreign( PathStringType *path ) {
#ifdef WIN32
ascii::replace_all( *path, '/', '\\' );
#else
@@ -87,13 +183,17 @@
return file;
}
-static type get_type( LPCWSTR wpath, size_type *size = nullptr ) {
+static type get_type( LPCWSTR wpath, info *pinfo = nullptr ) {
WIN32_FILE_ATTRIBUTE_DATA data;
if ( ::GetFileAttributesEx( wpath, GetFileExInfoStandard, (void*)&data ) ) {
- type const t = map_type( data.dwFileAttributes );
- if ( t == file && size )
- *size = ((size_type)data.nFileSizeHigh << 32) | data.nFileSizeLow;
- return t;
+ fs::type const type = map_type( data.dwFileAttributes );
+ if ( pinfo ) {
+ FILETIME const &ft = data.ftLastWriteTime;
+ pinfo->mtime = ((time_t)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
+ pinfo->size = ((size_type)data.nFileSizeHigh << 32) | data.nFileSizeLow;
+ pinfo->type = type;
+ }
+ return type;
}
return non_existent;
}
@@ -124,7 +224,8 @@
throw ZORBA_IO_EXCEPTION( "GetFullPathName()", path );
to_char( wfull_path, abs_path );
#else
- ::strcpy( abs_path, path );
+ if ( abs_path != path )
+ ::strcpy( abs_path, path );
#endif /* WINCE */
}
@@ -139,12 +240,12 @@
void chdir( char const *path ) {
#ifndef WIN32
if ( ::chdir( path ) != 0 )
- throw ZORBA_IO_EXCEPTION( "chdir()", path );
+ throw fs::exception( "chdir()", path );
#else
WCHAR wpath[ MAX_PATH ];
win32::to_wchar( path, wpath );
if ( ::_wchdir( wpath ) != 0 )
- throw fs::exception( "wchdir()", path );
+ throw fs::exception( "_wchdir()", path );
#endif /* WIN32 */
}
@@ -171,86 +272,28 @@
#endif /* ZORBA_WITH_FILE_ACCESS */
-zstring curdir() {
- char path[ MAX_PATH ];
+string curdir() {
#ifndef WIN32
- if ( !::getcwd( path, sizeof( path ) ) )
- throw ZORBA_IO_EXCEPTION( "getcwd()", "" );
+ static size_t size = PATH_MAX;
+ static unique_ptr<char[]> path( new char[ size ] );
+ while ( !::getcwd( path.get(), size ) ) {
+ if ( errno != ERANGE )
+ throw ZORBA_IO_EXCEPTION( "getcwd()", "" );
+ path.reset( new char[ size *= 2 ] );
+ }
+ return path.get();
#else
WCHAR wpath[ MAX_PATH ];
if ( !::GetCurrentDirectory( sizeof( wpath ) / sizeof( wpath[0] ), wpath ) )
throw ZORBA_IO_EXCEPTION( "GetCurrentDirectory()", "" );
+ char path[ MAX_PATH ];
win32::to_char( wpath, path );
if ( !is_absolute( path ) ) {
// GetCurrentDirectory() sometimes misses drive letter.
- filesystem_path fspath( path );
- fspath.resolve_relative();
- return fspath.get_path();
+ make_absolute( path );
}
-#endif /* WIN32 */
return path;
-}
-
-zstring get_normalized_path( char const *path, char const *base ) {
- if ( !path[0] )
- throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( ZED( EmptyPath ) ) );
- zstring result;
- if ( ascii::begins_with( path, "file://" ) ) {
- result = path + 7;
- if ( result.empty() )
- throw XQUERY_EXCEPTION(
- err::XPTY0004,
- ERROR_PARAMS( ZED( QuotedColon_23 ), path, ZED( EmptyPath ) )
- );
- zstring::size_type slash = result.find( '/' );
- if ( slash == zstring::npos )
- throw XQUERY_EXCEPTION(
- err::XPTY0004,
- ERROR_PARAMS( ZED( QuotedColon_23 ), path, ZED( BadPath ) )
- );
- if ( slash > 0 ) {
- zstring const authority( result.substr( 0, slash ) );
- if ( authority != "localhost" )
- throw XQUERY_EXCEPTION(
- err::XPTY0004,
- ERROR_PARAMS(
- ZED( QuotedColon_23 ), authority, ZED( NonLocalhostAuthority )
- )
- );
- }
-#ifdef WIN32
- ++slash; // skip leading '/' in "/C:/file.txt"
-#endif /* WIN32 */
- result = result.substr( slash );
- uri::decode( result );
-#ifdef WIN32
- replace_foreign( &result );
- if ( !is_absolute( result ) )
- throw XQUERY_EXCEPTION(
- err::XPTY0004,
- ERROR_PARAMS(
- ZED( QuotedColon_23 ), result, ZED( NoDriveSpecification )
- )
- );
-#endif /* WIN32 */
- } else {
- zstring path2( path );
- replace_foreign( &path2 );
- if ( !is_absolute( path2 ) && base && base[0] ) {
- result = base;
- replace_foreign( &result );
- append( result, path2 );
- } else
- result = path2;
-#ifdef WIN32
- while ( ascii::replace_all( result, "\\\\", 2, "\\", 1 ) )
- ;
-#else
- while ( ascii::replace_all( result, "//", 2, "/", 1 ) )
- ;
-#endif /* WIN32 */
- }
- return result;
+#endif /* WIN32 */
}
#ifdef ZORBA_WITH_FILE_ACCESS
@@ -275,31 +318,60 @@
#endif /* ZORBA_WITH_FILE_ACCESS */
-type get_type( char const *path, bool follow_symlink, size_type *size ) {
+type get_type( char const *path, bool follow_symlink, info *pinfo ) {
+ if ( pinfo )
+ ::memset( pinfo, 0, sizeof( info ) );
#ifndef WIN32
struct stat st_buf;
int const status = follow_symlink ?
::stat( path, &st_buf ) : ::lstat( path, &st_buf );
if ( status == -1 ) {
- if ( errno == ENOENT )
- return non_existent;
- throw ZORBA_IO_EXCEPTION( follow_symlink ? "stat()" : "lstat()", path );
+ switch ( errno ) {
+ case ENOENT:
+ return non_existent;
+ case EACCES:
+ case ELOOP:
+ case ENAMETOOLONG:
+ case ENOTDIR:
+ throw fs::exception( follow_symlink ? "stat()" : "lstat()", path );
+ default:
+ throw ZORBA_IO_EXCEPTION( follow_symlink ? "stat()" : "lstat()", path );
+ }
}
+
+ fs::type type;
if ( S_ISDIR( st_buf.st_mode ) )
- return directory;
- if ( S_ISLNK( st_buf.st_mode ) )
- return link;
- if ( S_ISREG( st_buf.st_mode ) ) {
- if ( size )
- *size = st_buf.st_size;
- return file;
+ type = directory;
+ else if ( S_ISLNK( st_buf.st_mode ) )
+ type = link;
+ else if ( S_ISREG( st_buf.st_mode ) )
+ type = file;
+ else
+ type = other;
+
+ if ( pinfo ) {
+ pinfo->mtime = st_buf.st_mtime;
+ pinfo->size = st_buf.st_size;
+ pinfo->type = type;
}
- return other;
+ return type;
#else
WCHAR wpath[ MAX_PATH ];
win32::to_wchar( path, wpath );
- return win32::get_type( wpath, size );
-#endif /* WIN32 */
+ return win32::get_type( wpath, pinfo );
+#endif /* WIN32 */
+}
+
+void make_absolute( char *path ) {
+ if ( !is_absolute( path ) ) {
+#ifndef WIN32
+ string abs_path( curdir() );
+ append( abs_path, path );
+ abs_path.copy( path, abs_path.size() );
+#else
+ win32::make_absolute_impl( path, path );
+#endif /* WIN32 */
+ }
}
#ifdef ZORBA_WITH_FILE_ACCESS
@@ -316,6 +388,27 @@
#endif
}
+string normalize_path( char const *path, char const *base ) {
+ if ( !path[0] )
+ throw invalid_argument( "empty path" );
+ string new_path;
+ if ( !parse_file_uri( path, &new_path ) ) {
+ //
+ // The path is an ordinary path.
+ //
+ string local_path( path );
+ replace_foreign( &local_path );
+ if ( !is_absolute( local_path ) && base && base[0] ) {
+ new_path = base;
+ replace_foreign( &new_path );
+ append( new_path, local_path );
+ } else
+ new_path = local_path;
+ }
+ canonicalize( &new_path );
+ return new_path;
+}
+
void iterator::ctor_impl() {
make_absolute( dir_path_ );
#ifndef WIN32
@@ -360,7 +453,7 @@
// This check fixes bug #1023862.
//
zstring ent_path( dir_path_ );
- fs::append( ent_path, ent_->d_name );
+ append( ent_path, ent_->d_name );
ent_type_ = get_type( ent_path );
if ( ent_type_ == directory && is_dots( ent_->d_name ) )
continue; // skip "." and ".." entries
@@ -427,20 +520,32 @@
}
#endif /* WIN32 */
-bool remove( char const *path ) {
+bool remove( char const *path, bool ignore_not_found ) {
#ifndef WIN32
- return ::remove( path ) == 0;
+ if ( ::remove( path ) == 0 )
+ return true;
+ if ( ignore_not_found && errno == ENOENT )
+ return false;
+ throw fs::exception( "remove()", path );
#else
WCHAR wpath[ MAX_PATH ];
win32::to_wchar( path, wpath );
- switch ( win32::get_type( wpath, NULL ) ) {
+ char const *win32_fn_name;
+
+ switch ( win32::get_type( wpath ) ) {
case directory:
- return ::RemoveDirectory( wpath ) != 0;
- case non_existent:
- return false;
+ win32_fn_name = "RemoveDirectory()";
+ if ( ::RemoveDirectory( wpath ) )
+ return true;
+ break;
default:
- return ::DeleteFile( wpath ) != 0;
+ win32_fn_name = "DeleteFile()";
+ if ( ::DeleteFile( wpath ) )
+ return true;
}
+ if ( ignore_not_found && ::GetLastError() == ERROR_FILE_NOT_FOUND )
+ return false;
+ throw fs::exception( win32_fn_name, path );
#endif /* WIN32 */
}
=== modified file 'src/util/fs_util.h'
--- src/util/fs_util.h 2013-05-09 00:48:27 +0000
+++ src/util/fs_util.h 2013-06-03 23:16:28 +0000
@@ -18,89 +18,15 @@
#define ZORBA_FS_UTIL_H
#include <zorba/config.h>
-
-#include <iostream>
-#include <stdexcept>
-#ifdef WIN32
-# include <windows.h>
-#else
-# include <dirent.h>
-# include <sys/types.h> /* for off_t */
-#endif /* WIN32 */
+#include <zorba/internal/cxx_util.h>
+#include <zorba/util/fs_util.h>
#include "ascii_util.h"
-#include "cxx_util.h"
-#include "error_util.h"
#include "string_util.h"
-#include "zorbatypes/zstring.h"
-
-#ifndef MAX_PATH
-/**
- * Maximum path length. This is defined under Windows to be 1024. There is no
- * equivalent constant/macro for *nix systems, so simply borrow Windows' value.
- */
-#define MAX_PATH 1024
-#endif /* MAX_PATH */
namespace zorba {
namespace fs {
-////////// constants //////////////////////////////////////////////////////////
-
-#ifdef WIN32
-char const dir_separator = '\\';
-char const path_separator = ';';
-#else
-char const dir_separator = '/';
-char const path_separator = ':';
-#endif /* WIN32 */
-
-////////// types //////////////////////////////////////////////////////////////
-
-/**
- * File size type.
- */
-#ifdef WIN32
-typedef __int64 size_type;
-#else
-typedef off_t size_type;
-#endif /* WIN32 */
-
-/**
- * File type.
- */
-enum type {
- non_existent,
- directory,
- file,
- link,
- volume,
- other // named pipe, character/block special, socket, etc.
-};
-extern char const *const type_string[];
-
-/**
- * Emits the string representation of a file type to the given ostream.
- *
- * @param o The ostream to emit to.
- * @param t The file type to emit.
- * @return Returns \a o.
- */
-inline std::ostream& operator<<( std::ostream &o, type t ) {
- return o << type_string[ t ];
-}
-
-////////// Windows ////////////////////////////////////////////////////////////
-
-#ifdef WIN32
-namespace win32 {
-
-// Do not use this function directly.
-void make_absolute_impl( char const *path, char *abs_path );
-
-} // namespace win32
-#endif /* WIN32 */
-
////////// Exceptions /////////////////////////////////////////////////////////
typedef os_error::exception exception;
@@ -130,142 +56,6 @@
#endif /* ZORBA_WITH_FILE_ACCESS */
-/**
- * Gets the current directory.
- *
- * @return Returns said directory.
- * @throws fs::exception if it fails.
- */
-zstring curdir();
-
-#ifdef ZORBA_WITH_FILE_ACCESS
-
-/**
- * Creates a directory.
- *
- * @param path The full path of the directory to create.
- * @throws fs::exception if the creation fails.
- */
-void mkdir( char const *path );
-
-/**
- * Creates a directory.
- *
- * @tparam PathStringType The \a path string type.
- * @param path The full path of the directory to create.
- * @throws fs::exception if the creation fails.
- */
-template<class PathStringType> inline
-typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),void>::type
-mkdir( PathStringType const &path ) {
- mkdir( path.c_str() );
-}
-
-////////// Directory iteration ////////////////////////////////////////////////
-
-/**
- * An %fs::iterator iterates over the entries in a directory.
- */
-class iterator {
-public:
- /**
- * Constructs an %iterator.
- *
- * @param path The full path to the directory to iterate over.
- * @throws fs::exception if the construction failed, e.g., path not found.
- */
- iterator( char const *path ) : dir_path_( path ) {
- ctor_impl();
- }
-
- /**
- * Constructs an %iterator.
- *
- * @tparam PathStringType The \a path string type.
- * @param path The full path to the directory to iterate over.
- * @throws fs::exception if the construction failed, e.g., path not found.
- */
- template<class PathStringType>
- iterator( PathStringType const &path,
- typename std::enable_if<ZORBA_HAS_C_STR(PathStringType)
- >::type* = 0 ) : dir_path_( path.c_str() ) {
- ctor_impl();
- }
-
- /**
- * Destroys this %iterator.
- */
- ~iterator();
-
- /**
- * Attempts to get the next directory entry.
- *
- * @return Returns \c true only if there is a next directory.
- */
- bool next();
-
- /**
- * Gets the name of the curent directory entry.
- *
- * @return Returns said name.
- */
- char const* entry_name() const {
-# ifndef WIN32
- return ent_->d_name;
-# else
- return ent_name_;
-# endif /* WIN32 */
- }
-
- /**
- * Gets the type of the current directory entry.
- *
- * @return Returns said type.
- */
- type entry_type() const {
- return ent_type_;
- }
-
- /**
- * Gets the directory's path.
- *
- * @return Returns said path.
- */
- char const* path() const {
- return dir_path_.c_str();
- }
-
- /**
- * Resets this iterator to the beginning.
- */
- void reset();
-
-private:
- zstring dir_path_;
- type ent_type_;
-#ifndef WIN32
- DIR *dir_;
- struct dirent *ent_;
-#else
- HANDLE dir_;
- bool dir_is_empty_;
- WIN32_FIND_DATA ent_data_;
- char ent_name_[ MAX_PATH ];
- bool use_first_;
-
- void win32_opendir( char const *path );
- void win32_closedir();
-#endif /* WIN32 */
-
- void ctor_impl();
-
- // forbid
- iterator( iterator const& );
- iterator& operator=( iterator const& );
-};
-
-#endif /* ZORBA_WITH_FILE_ACCESS */
-
////////// File creation //////////////////////////////////////////////////////
#ifdef ZORBA_WITH_FILE_ACCESS
@@ -298,27 +88,6 @@
#ifdef ZORBA_WITH_FILE_ACCESS
/**
- * Removes the given file or directory.
- *
- * @param path The full path of the file or directory to remove.
- * @return Returns \c true only if the file or directory was removed.
- */
-bool remove( char const *path );
-
-/**
- * Removes the given file or directory.
- *
- * @tparam PathStringType The \a path string type.
- * @param path The full path of the file or directory to remove.
- * @return Returns \c true only if the file or directory was removed.
- */
-template<class PathStringType> inline
-typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),bool>::type
-remove( PathStringType const &path ) {
- return remove( path.c_str() );
-}
-
-/**
* An %auto_remover is a simple class to guarantee that a file or directory
* referred to by a path is deleted upon the %auto_remover getting destroyed.
*
@@ -474,103 +243,6 @@
#endif /* ZORBA_WITH_FILE_ACCESS */
-////////// File information ///////////////////////////////////////////////////
-
-/**
- * Gets the base name of the given path name, i.e., the file name without the
- * path leading up to it.
- *
- * @param path The full path to get the base name of.
- * @return Returns the base name. Note that if \a path is just a file name,
- * then returns \a path.
- */
-inline char const* base_name( char const *path ) {
- if ( char const *const sep = ::strrchr( path, dir_separator ) )
- return sep + 1;
- return path;
-}
-
-/**
- * Gets the base name of the given path name, i.e., the file name without the
- * path leading up to it.
- *
- * @tparam PathStringType The \a path string type.
- * @param path The full path to get the base name of.
- * @return Returns the base name. Note that if \a path is just a file name,
- * then returns \a path.
- */
-template<class PathStringType> inline
-typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),char const*>::type
-base_name( PathStringType const &path ) {
- return base_name( path.c_str() );
-}
-
-/**
- * Gets the type of the given file.
- *
- * @param path The full path to check.
- * @param follow_symlink If \c true follows symbolic links.
- * @param size A pointer to a receive the size of the file in bytes. The size
- * is set only if it's not \c nullptr and the file's type is \c file.
- * @return If \a path refers to a symbolic link and \a follow_symlink is
- * \c true, the type returned is of that to which the link refers; if \a path
- * refers to a symbolic and \a follow_symlink is \c false, returns \c link; if
- * \a path does not refer to a symbolic link, returns the type of \a path.
- */
-type get_type( char const *path, bool follow_symlink = true,
- size_type *size = nullptr );
-
-/**
- * Gets the type of the given file.
- *
- * @tparam PathStringType The \a path string type.
- * @param path The full path to check.
- * @param follow_symlink If \c true follows symbolic links.
- * @param size A pointer to a receive the size of the file in bytes. The size
- * is set only if it's not \c nullptr and the file's type is \c file.
- * @return If \a path refers to a symbolic link and \a follow_symlink is
- * \c true, the type returned is of that to which the link refers; if \a path
- * refers to a symbolic and \a follow_symlink is \c false, returns \c link; if
- * \a path does not refer to a symbolic link, returns the type of \a path.
- */
-template<class PathStringType> inline
-typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),type>::type
-get_type( PathStringType const &path, bool follow_symlink = true,
- size_type *size = nullptr ) {
- return get_type( path.c_str(), follow_symlink, size );
-}
-
-/**
- * Checks whether the given path is an absolute path.
- *
- * @param path The full path to check.
- * @return Returns \c true only if the path is absolute.
- */
-inline bool is_absolute( char const *path ) {
-#ifndef WIN32
- return path[0] == '/';
-#else
- //
- // No, this should NOT also check for '/'. The path should have been
- // normalized for Windows first, i.e., have '/' replaced by '\'.
- //
- return ascii::is_alpha( path[0] ) && path[1] == ':' && path[2] == '\\';
-#endif /* WIN32 */
-}
-
-/**
- * Checks whether the given path is an absolute path.
- *
- * @tparam PathStringType The \a path string type.
- * @param path The full path to check.
- * @return Returns \c true only if the path is absolute.
- */
-template<class PathStringType> inline
-typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),bool>::type
-is_absolute( PathStringType const &path ) {
- return is_absolute( path.c_str() );
-}
-
////////// File renaming //////////////////////////////////////////////////////
#ifdef ZORBA_WITH_FILE_ACCESS
@@ -631,105 +303,6 @@
#endif /* ZORBA_WITH_FILE_ACCESS */
-////////// Path normalization /////////////////////////////////////////////////
-
-/**
- * Gets the normalized path of the given path.
- *
- * @param path The path to normalize.
- * @param base The base path, if any.
- * @return Returns the normalized path.
- * @throws XQueryException err::XPTY0004 for malformed paths.
- */
-zstring get_normalized_path( char const *path, char const *base = nullptr );
-
-/**
- * Gets the normalized path of the given path.
- *
- * @tparam PathStringType The \a path string type.
- * @param path The path to normalize.
- * @param base The base path, if any.
- * @return Returns the normalized path.
- * @throws XQueryException err::XPTY0004 for malformed paths.
- */
-template<class PathStringType> inline
-typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),zstring>::type
-get_normalized_path( PathStringType const &path,
- PathStringType const &base = "" ) {
- return get_normalized_path( path.c_str(), base.c_str() );
-}
-
-/**
- * Normalizes the given path.
- *
- * @tparam PathStringType The path string type.
- * @param path The path to normalize.
- * @param base The base path, if any.
- * @return Returns the normalized path.
- * @throws XQueryException err::XPTY0004 for malformed paths.
- */
-template<class PathStringType> inline
-typename std::enable_if<ZORBA_IS_STRING(PathStringType),void>::type
-normalize_path( PathStringType &path, PathStringType const &base = "" ) {
- path = get_normalized_path( path, base );
-}
-
-////////// Path manipulation //////////////////////////////////////////////////
-
-/**
- * Appends a path component onto another path ensuring that exactly one
- * separator is used.
- *
- * @tparam PathStringType1 The \a path1 string type.
- * @param path1 The path to append to.
- * @param path2 The path to append.
- */
-template<class PathStringType1> inline
-typename std::enable_if<ZORBA_IS_STRING(PathStringType1),void>::type
-append( PathStringType1 &path1, char const *path2 ) {
- if ( !ascii::ends_with( path1, dir_separator ) )
- path1 += dir_separator;
- path1 += path2;
-}
-
-/**
- * Appends a path component onto another path.
- *
- * @tparam PathStringType1 The \a path1 string type.
- * @tparam PathStringType2 The \a path2 string type.
- * @param path1 The path to append to.
- * @param path2 The path to append.
- */
-template<class PathStringType1,class PathStringType2> inline
-typename std::enable_if<ZORBA_IS_STRING(PathStringType1)
- && ZORBA_HAS_C_STR(PathStringType2),
- void>::type
-append( PathStringType1 &path1, PathStringType2 const &path2 ) {
- append( path1, path2.c_str() );
-}
-
-/**
- * Makes a relative path into an absolute path.
- *
- * @tparam PathStringType The \a path string type.
- * @param path The path to make absolute.
- */
-template<class PathStringType> inline
-typename std::enable_if<ZORBA_IS_STRING(PathStringType),void>::type
-make_absolute( PathStringType &path ) {
- if ( !is_absolute( path ) ) {
-#ifndef WIN32
- typedef typename PathStringType::size_type size_type;
- path.insert( static_cast<size_type>(0), static_cast<size_type>(1), '/' );
- path.insert( 0, curdir().c_str() );
-#else
- char temp[ MAX_PATH ];
- win32::make_absolute_impl( path.c_str(), temp );
- path = temp;
-#endif /* WIN32 */
- }
-}
-
////////// Temporary files ////////////////////////////////////////////////////
#ifdef ZORBA_WITH_FILE_ACCESS
=== modified file 'src/util/fx/fxcharheap.cpp'
--- src/util/fx/fxcharheap.cpp 2013-02-07 17:24:36 +0000
+++ src/util/fx/fxcharheap.cpp 2013-06-03 23:16:28 +0000
@@ -36,8 +36,6 @@
#include <sstream>
#include <iostream>
-#include <zorba/util/file.h>
-
#include "diagnostics/xquery_diagnostics.h"
using namespace std;
=== modified file 'src/util/hash/hashtable.h'
--- src/util/hash/hashtable.h 2013-02-07 17:24:36 +0000
+++ src/util/hash/hashtable.h 2013-06-03 23:16:28 +0000
@@ -23,8 +23,8 @@
#include <sys/types.h>
#include <utility> /* for pair */
-// local
-#include "util/cxx_util.h"
+// Zorba
+#include <zorba/internal/cxx_util.h>
#include "util/stl_util.h"
namespace zorba {
=== modified file 'src/util/hexbinary_util.h'
--- src/util/hexbinary_util.h 2013-05-09 00:48:27 +0000
+++ src/util/hexbinary_util.h 2013-06-03 23:16:28 +0000
@@ -23,7 +23,8 @@
#include <sys/types.h> /* for size_t */
#include <vector>
-#include "cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "stream_util.h"
namespace zorba {
=== modified file 'src/util/http_util.cpp'
--- src/util/http_util.cpp 2013-02-07 17:24:36 +0000
+++ src/util/http_util.cpp 2013-06-03 23:16:28 +0000
@@ -18,12 +18,14 @@
#include <iostream>
#include <sstream>
+#include <zorba/empty_sequence.h>
#include <zorba/singleton_item_sequence.h>
-#include <zorba/empty_sequence.h>
-#include <api/unmarshaller.h>
+#include <zorba/util/error_util.h>
+
+#include "api/unmarshaller.h"
+#include "zorbamisc/ns_consts.h"
+
#include "http_util.h"
-#include "error_util.h"
-#include "zorbamisc/ns_consts.h"
namespace zorba {
=== modified file 'src/util/icu_regex.cpp'
--- src/util/icu_regex.cpp 2013-04-19 04:07:25 +0000
+++ src/util/icu_regex.cpp 2013-06-03 23:16:28 +0000
@@ -23,12 +23,13 @@
#include <vector>
#include <zorba/diagnostic_list.h>
+#include <zorba/internal/cxx_util.h>
+
#include "diagnostics/assert.h"
#include "diagnostics/dict.h"
#include "diagnostics/xquery_exception.h"
#include "ascii_util.h"
-#include "cxx_util.h"
#include "regex.h"
#include "stl_util.h"
=== modified file 'src/util/icu_regex.h'
--- src/util/icu_regex.h 2013-04-12 05:26:54 +0000
+++ src/util/icu_regex.h 2013-06-03 23:16:28 +0000
@@ -17,7 +17,8 @@
#ifndef ZORBA_ICU_REGEX_H
#define ZORBA_ICU_REGEX_H
-#include "cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "unicode_util.h"
#include "zorbatypes/zstring.h"
=== modified file 'src/util/icu_streambuf.cpp'
--- src/util/icu_streambuf.cpp 2013-05-08 01:05:04 +0000
+++ src/util/icu_streambuf.cpp 2013-06-03 23:16:28 +0000
@@ -27,11 +27,11 @@
#include <zorba/config.h>
#include <zorba/diagnostic_list.h>
+#include <zorba/internal/cxx_util.h>
#include "diagnostics/assert.h"
#include "diagnostics/diagnostic.h"
#include "diagnostics/zorba_exception.h"
-#include "util/cxx_util.h"
#include "util/string_util.h"
#include "util/utf8_util.h"
=== modified file 'src/util/json_parser.h'
--- src/util/json_parser.h 2013-02-07 17:24:36 +0000
+++ src/util/json_parser.h 2013-06-03 23:16:28 +0000
@@ -24,11 +24,11 @@
#include <stack>
#include <string>
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/diagnostic.h>
#include "zorbatypes/zstring.h"
-#include "cxx_util.h"
#include "unicode_util.h"
namespace zorba {
=== modified file 'src/util/mem_streambuf.cpp'
--- src/util/mem_streambuf.cpp 2013-04-16 22:12:03 +0000
+++ src/util/mem_streambuf.cpp 2013-06-03 23:16:28 +0000
@@ -17,9 +17,10 @@
#include "stdafx.h"
#include <cstring> /* for memcpy(3) */
+#include <zorba/internal/cxx_util.h>
+
#include "diagnostics/assert.h"
-#include "cxx_util.h"
#include "mem_streambuf.h"
using namespace std;
=== modified file 'src/util/mmap_file.cpp'
--- src/util/mmap_file.cpp 2013-02-07 17:24:36 +0000
+++ src/util/mmap_file.cpp 2013-06-03 23:16:28 +0000
@@ -22,8 +22,9 @@
# include <unistd.h> /* for close(2) */
#endif /* WIN32 */
-#include "cxx_util.h"
-#include "error_util.h"
+#include <zorba/internal/cxx_util.h>
+#include <zorba/util/error_util.h>
+
#include "diagnostics/xquery_diagnostics.h"
#include "mmap_file.h"
=== modified file 'src/util/stl_util.h'
--- src/util/stl_util.h 2013-05-16 17:34:43 +0000
+++ src/util/stl_util.h 2013-06-03 23:16:28 +0000
@@ -27,10 +27,9 @@
#include <stack>
#include <zorba/config.h>
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/ztd.h>
-#include "cxx_util.h"
-
namespace zorba {
namespace ztd {
=== modified file 'src/util/stream_util.cpp'
--- src/util/stream_util.cpp 2013-05-08 01:05:04 +0000
+++ src/util/stream_util.cpp 2013-06-03 23:16:28 +0000
@@ -15,9 +15,13 @@
*/
#include "stdafx.h"
+// standard
+#include <cstring> /* for memcmp(3) */
+
// local
#include "ascii_util.h"
#include "stream_util.h"
+#include "utf8_util.h"
using namespace std;
@@ -103,6 +107,16 @@
return o;
}
+bool skip_utf8_bom( istream &is ) {
+ char buf[ sizeof utf8::BOM ];
+ if ( is.read( buf, sizeof buf ) ) {
+ if ( ::memcmp( buf, utf8::BOM, sizeof utf8::BOM ) == 0 )
+ return true;
+ is.seekg( 0 );
+ }
+ return false;
+}
+
///////////////////////////////////////////////////////////////////////////////
} // namespace zorba
=== modified file 'src/util/string/buf_rep.h'
--- src/util/string/buf_rep.h 2013-02-07 17:24:36 +0000
+++ src/util/string/buf_rep.h 2013-06-03 23:16:28 +0000
@@ -21,10 +21,10 @@
#include <stdexcept>
#include <zorba/config.h>
+#include <zorba/internal/cxx_util.h>
#include "rep_base.h"
#include "rep_proxy.h"
-#include "util/cxx_util.h"
#include "util/void_int.h"
namespace zorba {
=== modified file 'src/util/string/default_rep.h'
--- src/util/string/default_rep.h 2013-02-07 17:24:36 +0000
+++ src/util/string/default_rep.h 2013-06-03 23:16:28 +0000
@@ -19,7 +19,8 @@
#include <iterator>
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "rep_base.h"
namespace zorba {
=== modified file 'src/util/string/ptr_rep.h'
--- src/util/string/ptr_rep.h 2013-02-07 17:24:36 +0000
+++ src/util/string/ptr_rep.h 2013-06-03 23:16:28 +0000
@@ -19,7 +19,8 @@
#include <iterator>
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "rep_base.h"
namespace zorba {
=== modified file 'src/util/string/rep_proxy.h'
--- src/util/string/rep_proxy.h 2013-02-07 17:24:36 +0000
+++ src/util/string/rep_proxy.h 2013-06-03 23:16:28 +0000
@@ -20,8 +20,7 @@
#include <cassert>
#include <zorba/config.h>
-
-#include "util/cxx_util.h"
+#include <zorba/internal/cxx_util.h>
namespace zorba {
namespace rstring_classes {
=== modified file 'src/util/string/rstring.h'
--- src/util/string/rstring.h 2013-02-07 17:24:36 +0000
+++ src/util/string/rstring.h 2013-06-03 23:16:28 +0000
@@ -23,8 +23,9 @@
#include <stdexcept>
#include <string>
+#include <zorba/internal/cxx_util.h>
+
#include "rep_proxy.h"
-#include "util/cxx_util.h"
namespace zorba {
=== modified file 'src/util/string_util.cpp'
--- src/util/string_util.cpp 2013-05-23 00:52:57 +0000
+++ src/util/string_util.cpp 2013-06-03 23:16:28 +0000
@@ -18,8 +18,9 @@
#include <cerrno>
#include <cstdlib>
+#include <zorba/internal/cxx_util.h>
+
#include "ascii_util.h"
-#include "cxx_util.h"
#include "string_util.h"
#include "zorbatypes/zstring.h"
=== modified file 'src/util/string_util.h'
--- src/util/string_util.h 2013-05-09 00:48:27 +0000
+++ src/util/string_util.h 2013-06-03 23:16:28 +0000
@@ -27,9 +27,9 @@
#include <string>
// Zorba
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/ztd.h>
#include "ascii_util.h"
-#include "cxx_util.h"
#include "stl_util.h"
#include "zorbatypes/zstring.h"
=== modified file 'src/util/time_parse.cpp'
--- src/util/time_parse.cpp 2013-05-08 01:05:04 +0000
+++ src/util/time_parse.cpp 2013-06-03 23:16:28 +0000
@@ -21,8 +21,8 @@
#include <string>
// Zorba
+#include <zorba/internal/cxx_util.h>
#include "ascii_util.h"
-#include "cxx_util.h"
#include "string_util.h"
#include "zorbatypes/zstring.h"
#include "zorbautils/locale.h"
=== modified file 'src/util/time_parse.h'
--- src/util/time_parse.h 2013-05-08 01:05:04 +0000
+++ src/util/time_parse.h 2013-06-03 23:16:28 +0000
@@ -22,7 +22,7 @@
// Zorba
#include <zorba/config.h>
-#include "cxx_util.h"
+#include <zorba/internal/cxx_util.h>
#include "string_util.h"
#include "time_util.h"
#include "zorbautils/locale.h"
=== modified file 'src/util/time_util.h'
--- src/util/time_util.h 2013-05-08 01:05:04 +0000
+++ src/util/time_util.h 2013-06-03 23:16:28 +0000
@@ -25,8 +25,8 @@
// Zorba
#include <zorba/config.h>
+#include <zorba/internal/cxx_util.h>
#include <zorba/time.h>
-#include "cxx_util.h"
#include "string_util.h"
#ifndef TM_YEAR_BASE
=== modified file 'src/util/unicode_util.cpp'
--- src/util/unicode_util.cpp 2013-04-25 02:05:20 +0000
+++ src/util/unicode_util.cpp 2013-06-03 23:16:28 +0000
@@ -28,8 +28,8 @@
# include <unicode/ustring.h>
#endif /* ZORBA_NO_ICU */
+#include <zorba/internal/cxx_util.h>
#include "ascii_util.h"
-#include "cxx_util.h"
#include "unicode_util.h"
#include "utf8_util.h"
=== modified file 'src/util/unordered_map.h'
--- src/util/unordered_map.h 2013-02-07 17:24:36 +0000
+++ src/util/unordered_map.h 2013-06-03 23:16:28 +0000
@@ -27,6 +27,8 @@
// standard
#include <utility> /* for pair */
+#include <zorba/internal/cxx_util.h>
+
// local
#include "util/hash/hash.h"
#include "util/hash/hashtable.h"
@@ -34,7 +36,6 @@
#ifndef ZORBA_UNORDERED_MAP_REHASH_POLICY
# define ZORBA_UNORDERED_MAP_REHASH_POLICY zorba::ztd::prime_rehash_policy
#endif /* ZORBA_UNORDERED_MAP_REHASH_POLICY */
-#include "cxx_util.h"
#include "stl_util.h"
namespace std {
=== modified file 'src/util/unordered_set.h'
--- src/util/unordered_set.h 2012-06-05 14:16:41 +0000
+++ src/util/unordered_set.h 2013-06-03 23:16:28 +0000
@@ -24,6 +24,8 @@
# include <unordered_set> /* use the implementation version */
#else
+#include <zorba/internal/cxx_util.h>
+
// local
#include "util/hash/hash.h"
#include "util/hash/hashtable.h"
@@ -31,7 +33,6 @@
#ifndef ZORBA_UNORDERED_SET_REHASH_POLICY
# define ZORBA_UNORDERED_SET_REHASH_POLICY zorba::ztd::prime_rehash_policy
#endif /* ZORBA_UNORDERED_SET_REHASH_POLICY */
-#include "cxx_util.h"
#include "stl_util.h"
namespace std {
=== modified file 'src/util/uri_util.cpp'
--- src/util/uri_util.cpp 2013-02-07 17:24:36 +0000
+++ src/util/uri_util.cpp 2013-06-03 23:16:28 +0000
@@ -112,7 +112,7 @@
switch ( get_scheme( uri ) ) {
case file:
case none:
- zpath = fs::get_normalized_path( uri );
+ zpath = fs::normalize_path( uri );
break;
default:
fs::get_temp_file( &zpath );
=== modified file 'src/util/uri_util.h'
--- src/util/uri_util.h 2013-05-29 04:36:02 +0000
+++ src/util/uri_util.h 2013-06-03 23:16:28 +0000
@@ -17,11 +17,13 @@
#ifndef ZORBA_URI_UTIL_H
#define ZORBA_URI_UTIL_H
+// standard
#include <algorithm>
#include <iostream>
-#include "cxx_util.h"
-#include "error_util.h"
+// Zorba
+#include <zorba/internal/cxx_util.h>
+#include <zorba/util/error_util.h>
#include "fs_util.h"
#include "stl_util.h"
=== modified file 'src/util/utf8_streambuf.cpp'
--- src/util/utf8_streambuf.cpp 2013-04-25 02:05:20 +0000
+++ src/util/utf8_streambuf.cpp 2013-06-03 23:16:28 +0000
@@ -26,10 +26,10 @@
#include <zorba/config.h>
#include <zorba/diagnostic_list.h>
+#include <zorba/internal/cxx_util.h>
#include "diagnostics/diagnostic.h"
#include "diagnostics/zorba_exception.h"
-#include "util/cxx_util.h"
#include "util/oseparator.h"
#include "util/string_util.h"
#include "util/utf8_util.h"
=== modified file 'src/util/utf8_util.cpp'
--- src/util/utf8_util.cpp 2013-04-25 02:47:31 +0000
+++ src/util/utf8_util.cpp 2013-06-03 23:16:28 +0000
@@ -19,13 +19,16 @@
#include <algorithm>
#include <cstring>
+// ICU
#ifndef ZORBA_NO_ICU
#include <unicode/ustring.h>
#endif /* ZORBA_NO_ICU */
+// Zorba
+#include <zorba/internal/cxx_util.h>
+
// local
#include "ascii_util.h"
-#include "cxx_util.h"
#include "utf8_util.h"
using namespace std;
=== modified file 'src/util/utf8_util.h'
--- src/util/utf8_util.h 2013-05-09 00:48:27 +0000
+++ src/util/utf8_util.h 2013-06-03 23:16:28 +0000
@@ -21,8 +21,9 @@
#include <cwchar>
#include <string>
+#include <zorba/internal/cxx_util.h>
+
#include "ascii_util.h"
-#include "cxx_util.h"
#include "string_util.h"
#include "unicode_util.h"
#include "utf8_string.h"
=== modified file 'src/util/zorba_regex.h'
--- src/util/zorba_regex.h 2013-04-12 04:34:41 +0000
+++ src/util/zorba_regex.h 2013-06-03 23:16:28 +0000
@@ -21,7 +21,8 @@
#ifdef ZORBA_NO_ICU
-#include "cxx_util.h"
+#include <zorba/internal/cxx_util.h>
+
#include "unicode_util.h"
#include "zorba_regex_engine.h"
#include "zorbatypes/zstring.h"
=== modified file 'src/zorbatypes/URI.cpp'
--- src/zorbatypes/URI.cpp 2013-05-08 01:17:03 +0000
+++ src/zorbatypes/URI.cpp 2013-06-03 23:16:28 +0000
@@ -21,8 +21,6 @@
#include "diagnostics/dict.h"
#include "diagnostics/assert.h"
-#include <zorba/util/path.h>
-
#include "URI.h"
#include "util/ascii_util.h"
=== modified file 'src/zorbatypes/ft_token.cpp'
--- src/zorbatypes/ft_token.cpp 2013-02-07 17:24:36 +0000
+++ src/zorbatypes/ft_token.cpp 2013-06-03 23:16:28 +0000
@@ -17,10 +17,11 @@
#include <string>
+#include <zorba/internal/cxx_util.h>
+
#include "diagnostics/assert.h"
#include "runtime/full_text/ft_wildcard.h"
#include "runtime/full_text/stemmer.h"
-#include "util/cxx_util.h"
#include "util/stl_util.h"
#include "util/unicode_util.h"
#include "util/utf8_util.h"
=== modified file 'src/zorbatypes/ft_token.h'
--- src/zorbatypes/ft_token.h 2013-02-07 17:24:36 +0000
+++ src/zorbatypes/ft_token.h 2013-06-03 23:16:28 +0000
@@ -20,9 +20,9 @@
#include <iostream>
#include <vector>
+#include <zorba/internal/cxx_util.h>
#include <zorba/locale.h>
-#include "util/cxx_util.h"
#include "zorbatypes/zstring.h"
namespace zorba {
=== modified file 'src/zorbatypes/integer.cpp'
--- src/zorbatypes/integer.cpp 2013-05-20 20:46:56 +0000
+++ src/zorbatypes/integer.cpp 2013-06-03 23:16:28 +0000
@@ -21,8 +21,8 @@
#include <cstdlib>
// Zorba
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/unique_ptr.h>
-#include "util/cxx_util.h"
#include "util/string_util.h"
// local
=== modified file 'src/zorbautils/locale.cpp'
--- src/zorbautils/locale.cpp 2013-05-18 00:53:20 +0000
+++ src/zorbautils/locale.cpp 2013-06-03 23:16:28 +0000
@@ -30,9 +30,9 @@
#endif /* WIN32 */
// Zorba
+#include <zorba/internal/cxx_util.h>
#include <zorba/internal/unique_ptr.h>
#include "util/ascii_util.h"
-#include "util/cxx_util.h"
#include "util/less.h"
#include "util/stl_util.h"
#include "util/string_util.h"
=== modified file 'test/apitest.cpp'
--- test/apitest.cpp 2013-05-28 00:58:27 +0000
+++ test/apitest.cpp 2013-06-03 23:16:28 +0000
@@ -31,7 +31,7 @@
#include <zorba/store_manager.h>
#include <zorba/iterator.h>
-#include <zorba/util/path.h>
+#include <zorba/util/fs_util.h>
#include <zorba/xquery_exception.h>
// Global variable g_abort_on_error is used to generate an abort() when an
@@ -132,17 +132,16 @@
// input file (either from a file or given as parameter)
auto_ptr<istream> qfile;
- filesystem_path path;
+ std::string path;
if (! lProp->inlineQuery())
{
path = lProp->queryFile ();
- path.resolve_relative ();
- std::string fname = path.get_path ();
- qfile.reset (new ifstream (fname.c_str ()));
+ fs::make_absolute( path );
+ qfile.reset (new ifstream (path.c_str ()));
if (!qfile->good() || qfile->eof())
{
- cerr << "no query given or not readable " << fname << endl;
+ cerr << "no query given or not readable " << path << endl;
return 3;
}
}
@@ -187,7 +186,7 @@
if (! lProp->inlineQuery())
{
- query->setFileName(path.get_path());
+ query->setFileName(path);
}
if (lProp->jsoniqParser())
@@ -212,7 +211,7 @@
{
std::string binary_path;
if (lProp->inlineQuery())
- binary_path = path.get_path() + ".plan";
+ binary_path = path + ".plan";
else
binary_path = "./temp.plan";
@@ -236,7 +235,7 @@
{
std::string binary_path;
if (lProp->inlineQuery())
- binary_path = path.get_path() + ".plan";
+ binary_path = path + ".plan";
else
binary_path = "./temp.plan";
query = zengine->createQuery();
=== modified file 'test/driver/sax2testdriver.cpp'
--- test/driver/sax2testdriver.cpp 2013-05-16 08:22:46 +0000
+++ test/driver/sax2testdriver.cpp 2013-06-03 23:16:28 +0000
@@ -24,7 +24,7 @@
#include <cassert>
#include <cstring>
-#include <zorba/util/file.h>
+#include <zorba/util/fs_util.h>
#include "testdriverconfig.h" // SRC and BIN dir definitions
@@ -220,11 +220,12 @@
// aCol contains the column number in which the first difference occurs
// aPos is the character number off the first difference in the file
// -1 is returned for aLine, aCol, and aPos if the files are equal
+#if 0
bool
isEqual(zorba::file aRefFile, zorba::file aResFile, int& aLine, int& aCol, int& aPos)
{
- std::ifstream li(aRefFile.get_path().c_str());
- std::ifstream ri(aResFile.get_path().c_str());
+ std::ifstream li(aRefFile.c_str());
+ std::ifstream ri(aResFile.c_str());
std::string lLine, rLine;
@@ -248,6 +249,7 @@
return true;
}
+#endif
void
slurp_file (const char *fname, std::string &result) {
@@ -273,46 +275,49 @@
main(int argc, char** argv)
#endif
{
- int flags = zorba::file::CONVERT_SLASHES | zorba::file::RESOLVE;
-
// do initial stuff
if ( argc != 2 ) {
- std::cerr << "\nusage: testdriver [testfile]" << std::endl;
+ std::cerr << "\nusage: testdriver [testfile]" << std::endl;
return 1;
}
- std::string lQueryFileString = zorba::SAX2_SRC_DIR +"/Queries/" + argv[1];
- zorba::file lQueryFile (lQueryFileString, zorba::file::CONVERT_SLASHES | zorba::file::RESOLVE);
+
+ std::string lQueryFile( zorba::SAX2_SRC_DIR );
+ fs::append( lQueryFile, "Queries" );
+ fs::append( lQueryFile, argv[1] );
std::string lQueryWithoutSuffix = std::string(argv[1]).substr( 0, std::string(argv[1]).size()-3 );
std::cout << "test " << lQueryWithoutSuffix << std::endl;
- zorba::file lResultFile (zorba::SAX2_BINARY_DIR +"/QueryResults/"
- + lQueryWithoutSuffix + ".res", flags);
- zorba::file lErrorFile (zorba::SAX2_BINARY_DIR +"/"
- + lQueryWithoutSuffix + ".err", flags);
- zorba::file lRefFile (zorba::SAX2_SRC_DIR +"/ExpQueryResults/"
- + lQueryWithoutSuffix +".xml.res", flags);
+
+ std::string lResultFile( zorba::SAX2_BINARY_DIR );
+ fs::append( lResultFile, "QueryResults" );
+ fs::append( lResultFile, lQueryWithoutSuffix );
+ lResultFile += ".res";
+
+ std::string lErrorFile( zorba::SAX2_BINARY_DIR );
+ fs::append( lErrorFile, lQueryWithoutSuffix );
+ lErrorFile += ".err";
+
+ std::string lRefFile( zorba::SAX2_SRC_DIR );
+ fs::append( lRefFile, "ExpQueryResults" );
+ fs::append( lRefFile, lQueryWithoutSuffix );
+ lRefFile += ".xml.res";
- // does the query file exists
- if ( (! lQueryFile.exists ()) || lQueryFile.is_directory () ) {
- std::cerr << "\n query file " << lQueryFile.get_path()
+ if ( fs::get_type( lQueryFile ) != fs::file ) {
+ std::cerr << "\n query file " << lQueryFile
<< " does not exist or is not a file" << std::endl;
return 2;
}
- // delete previous files if they exists
- if ( lResultFile.exists () ) { lResultFile.remove (); }
- if ( lErrorFile.exists () ) { lErrorFile.remove (); }
+ fs::remove( lResultFile, true );
+ fs::remove( lErrorFile, true );
- // we must either have a reference file or an expected error code
- if ( (! lRefFile.exists ()) || lRefFile.is_directory ())
- {
+ if ( fs::get_type( lRefFile ) != fs::file ) {
std::cerr << "No reference result and no expected errors." << std::endl;
return 3;
}
- // print the query
std::cout << "Query:" << std::endl;
- printFile(std::cout, lQueryFile.get_path());
+ printFile(std::cout, lQueryFile);
std::cout << std::endl;
zorba::Zorba *engine = zorba::Zorba::getInstance(zorba::StoreManager::getStore());
@@ -323,7 +328,7 @@
// create and compile the query
std::string lQueryString;
- slurp_file(lQueryFile.get_path().c_str(), lQueryString);
+ slurp_file(lQueryFile.c_str(), lQueryString);
zorba::XQuery_t lQuery = engine->compileQuery(lQueryString.c_str(), getCompilerHints(), &errHandler);
if (errHandler.errors())
@@ -333,7 +338,7 @@
{
// serialize xml
- std::ofstream lResFileStream(lResultFile.get_path().c_str());
+ std::ofstream lResFileStream(lResultFile.c_str());
assert (lResFileStream.good());
lQuery->registerSAXHandler(&contentHandler);
@@ -348,7 +353,7 @@
}
}
std::cout << "Result:" << std::endl;
- printFile(std::cout, lResultFile.get_path());
+ printFile(std::cout, lResultFile);
std::cout << "=== end of result ===" << std::endl;
std::cout.flush();
@@ -361,7 +366,7 @@
if ( !lRes ) // results differ
{
std::cerr << std::endl << "Result does not match expected result:" << std::endl;
- printFile(std::cerr, lRefFile.get_path());
+ printFile(std::cerr, lRefFile);
std::cerr << "=== end of expected result ===" << std::endl;
std::cerr << "See line " << lLine << ", col " << lCol+1 << " of expected result. " << std::endl;
=== modified file 'test/driver/testdriver.cpp'
--- test/driver/testdriver.cpp 2013-05-28 01:14:15 +0000
+++ test/driver/testdriver.cpp 2013-06-03 23:16:28 +0000
@@ -36,9 +36,9 @@
#include "system/properties.h"
#include <zorba/static_context.h>
-#include <zorba/util/file.h>
+#include <zorba/util/fs_util.h>
-#include <zorbatypes/URI.h>
+#include "zorbatypes/URI.h"
#include "util/ascii_util.h"
#include <zorba/store_manager.h>
@@ -133,29 +133,22 @@
for (int testcnt = 1; i < argc; ++i, ++testcnt)
{
- std::string Queriesdir = "/Queries/";
-
- int path_flags = zorba::file::CONVERT_SLASHES | zorba::file::RESOLVE;
-
- std::string lQueryFileString = rbkt_src_dir + Queriesdir + argv[i];
+ std::string lQueryFile( rbkt_src_dir );
+ zorba::fs::append( lQueryFile, "Queries" );
+ zorba::fs::append( lQueryFile, argv[i] );
#ifndef ZORBA_TEST_PLAN_SERIALIZATION_EXECUTION_ONLY
- // Form the full pathname for the file containing the query and make sure
- // that the file exists.
- zorba::file lQueryFile (lQueryFileString, path_flags);
-
- if ( (! lQueryFile.exists ()) || lQueryFile.is_directory () )
- {
- std::cout << "\n query file " << lQueryFile.get_path()
+ if ( zorba::fs::get_type( lQueryFile ) != zorba::fs::file ) {
+ std::cout << "\n query file " << lQueryFile
<< " does not exist or is not a file" << std::endl;
return 2;
}
-#endif//ZORBA_TEST_PLAN_SERIALIZATION_EXECUTION_ONLY
+#endif /* ZORBA_TEST_PLAN_SERIALIZATION_EXECUTION_ONLY */
// Check if this is w3c_testsuite test.
- std::string path = lQueryFileString;
- bool isW3CXQTStest = ( path.find ( "w3c_testsuite" ) != std::string::npos );
- bool isW3CFTtest = ( path.find ( "w3c_full_text_testsuite" ) != std::string::npos );
+ std::string path = lQueryFile;
+ bool isW3CXQTStest = path.find( "w3c_testsuite" ) != std::string::npos;
+ bool isW3CFTtest = path.find( "w3c_full_text_testsuite" ) != std::string::npos;
bool isW3Ctest = isW3CFTtest || isW3CXQTStest;
std::string lQueryWithoutSuffix =
std::string(argv[i]).substr( 0, std::string(argv[i]).rfind('.') );
@@ -212,24 +205,26 @@
std::cout << "test " << lQueryWithoutSuffix << std::endl;
#ifndef ZORBA_TEST_PLAN_SERIALIZATION_COMPILE_ONLY
- zorba::file lResultFile (rbkt_bin_dir + "/QueryResults/"
- + lQueryWithoutSuffix + ".xml.res", path_flags);
+ std::string lResultFile( rbkt_bin_dir );
+ zorba::fs::append( lResultFile, "QueryResults" );
+ zorba::fs::append( lResultFile, lQueryWithoutSuffix );
+ lResultFile += ".xml.res";
- if ( lResultFile.exists () ) { lResultFile.remove (); }
+ zorba::fs::remove( lResultFile, true );
// Form the full pathname for the .spec file that may be associated
// with this query. If the .spec file exists, read its contents to
// extract args to be passed to the query (e.g., external var bindings),
// exprected errors, or the pathnames of reference-result files.
- zorba::file lSpecFile(rbkt_src_dir + "/Queries/" + lQueryWithoutSuffix + ".spec",
- path_flags);
+ std::string lSpecFile( rbkt_src_dir );
+ zorba::fs::append( lSpecFile, "Queries" );
+ zorba::fs::append( lSpecFile, lQueryWithoutSuffix );
+ lSpecFile += ".spec";
- if ( lSpecFile.exists ()) {
- bool lParsed = lSpec.parseFile(lSpecFile.get_path(), rbkt_src_dir,
- rbkt_bin_dir);
+ if ( zorba::fs::get_type( lSpecFile ) ) {
+ bool lParsed = lSpec.parseFile(lSpecFile, rbkt_src_dir, rbkt_bin_dir);
if (!lParsed) {
- std::cout << "Spec file " << lSpecFile.get_path() << " is malformed!"
- << std::endl;
+ std::cout << "Spec file " << lSpecFile << " is malformed!" << std::endl;
return 1;
}
}
@@ -255,21 +250,21 @@
// Get the pathnames of the reference-result files found in the .spec
// file (if any).
- std::vector<zorba::file> lRefFiles;
+ std::vector<std::string> lRefFiles;
bool lRefFileExists = false;
for (std::vector<std::string>::const_iterator lIter = lSpec.resultsBegin();
lIter != lSpec.resultsEnd();
++lIter)
{
- zorba::file lRefFile(*lIter, path_flags);
- if (lRefFile.exists())
+ std::string lRefFile(*lIter);
+ if ( zorba::fs::get_type( lRefFile ) )
{
lRefFileExists = true;
}
else
{
std::cout << "Warning: missing reference result file "
- << lRefFile.get_path () << std::endl;
+ << lRefFile << std::endl;
}
lRefFiles.push_back(lRefFile);
}
@@ -292,9 +287,12 @@
lRefFileTmpString = lRefFileTmpString.erase(pos, 7);
}
- lRefFiles.push_back(zorba::file(rbkt_src_dir + "/ExpQueryResults/" +
- lRefFileTmpString + ".xml.res"));
- if (lRefFiles [0].exists())
+ std::string lRefFile( rbkt_src_dir );
+ zorba::fs::append( lRefFile, "ExpQueryResults" );
+ zorba::fs::append( lRefFile, lRefFileTmpString );
+ lRefFile += ".xml.res";
+ lRefFiles.push_back( lRefFile );
+ if ( zorba::fs::get_type( lRefFiles[0] ) )
lRefFileExists = true;
}
#endif//ZORBA_TEST_PLAN_SERIALIZATION_COMPILE_ONLY
@@ -302,7 +300,7 @@
#ifndef ZORBA_TEST_PLAN_SERIALIZATION_EXECUTION_ONLY
// print the query
std::cout << "=== Query: ===" << std::endl;
- zorba::printFile(std::cout, lQueryFile.get_path());
+ zorba::printFile(std::cout, lQueryFile);
std::cout << "=== end of Query ===" << std::endl;
#endif
@@ -319,13 +317,13 @@
#ifndef ZORBA_TEST_PLAN_SERIALIZATION_EXECUTION_ONLY
// create and compile the query
std::string lQueryString;
- slurp_file(lQueryFile.get_path().c_str(), lQueryString, rbkt_src_dir, rbkt_bin_dir);
+ slurp_file(lQueryFile.c_str(), lQueryString, rbkt_src_dir, rbkt_bin_dir);
lQuery = engine->createQuery(&errHandler);
- lQuery->setFileName(lQueryFile.get_path());
+ lQuery->setFileName(lQueryFile);
bool lJSONiqMode =
- (lQueryFile.get_path().rfind(".jq") == lQueryFile.get_path().size() - 3);
+ (lQueryFile.rfind(".jq") == lQueryFile.size() - 3);
if (lJSONiqMode) lContext->setJSONiqVersion(zorba::jsoniq_version_1_0);
lQuery->compile(lQueryString.c_str(), lContext, getCompilerHints());
@@ -424,7 +422,7 @@
errors = -1;
{
// serialize xml/txt
- std::ofstream lResFileStream(lResultFile.get_path().c_str());
+ std::ofstream lResFileStream(lResultFile.c_str());
assert (lResFileStream.good());
// QQQ all this code should be in testdriver_common and used by
// testdriver_mt as well
@@ -484,14 +482,15 @@
{
std::cout << " " << *lIter;
}
- if ( lResultFile.exists () && lResultFile.get_size () == 0)
+ zorba::fs::info fs_info;
+ if ( zorba::fs::get_type( lResultFile, &fs_info ) && !fs_info.size )
{
std::cout << " but got empty result" << std::endl;
}
else
{
std::cout << " but got result:" << std::endl;
- zorba::printFile(std::cout, lResultFile.get_path());
+ zorba::printFile(std::cout, lResultFile);
std::cout << "=== end of result ===" << std::endl;
}
return 7;
@@ -506,12 +505,12 @@
else if( errors == -1 )
{
std::cout << "=== Result: ===" << std::endl;
- zorba::printFile(std::cout, lResultFile.get_path());
+ zorba::printFile(std::cout, lResultFile);
std::cout << "=== end of result ===" << std::endl;
std::cout.flush();
size_t i = 1;
bool lResultMatches = false;
- for (std::vector<zorba::file>::const_iterator lIter = lRefFiles.begin();
+ for (std::vector<std::string>::const_iterator lIter = lRefFiles.begin();
lIter != lRefFiles.end(); ++lIter)
{
int lLine, lCol; // where do the files differ
=== modified file 'test/driver/updtestdriver.cpp'
--- test/driver/updtestdriver.cpp 2013-05-28 01:34:25 +0000
+++ test/driver/updtestdriver.cpp 2013-06-03 23:16:28 +0000
@@ -20,8 +20,8 @@
#include <vector>
#include <string>
#include <cstring>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstdlib>
#include <cstring>
#include "testdriverconfig.h" // SRC and BIN dir definitions
@@ -33,11 +33,11 @@
#include <zorba/diagnostic_handler.h>
#include <zorba/zorba_exception.h>
#include <zorba/zorba_string.h>
-#include <zorba/util/file.h>
#include <zorba/static_context_consts.h>
#include <zorba/store_consts.h>
#include "util/ascii_util.h"
+#include "util/fs_util.h"
#include <zorba/store_manager.h>
@@ -105,10 +105,10 @@
if (!inlineFile)
{
zorba::Item lItem = lFactory->createString(val);
- if(name != ".")
- dctx->setVariable (name, lItem);
- else
- dctx->setContextItem (lItem);
+ if(name != ".")
+ dctx->setVariable (name, lItem);
+ else
+ dctx->setContextItem (lItem);
}
else
{
@@ -232,7 +232,6 @@
zorba::Zorba* engine = zorba::Zorba::getInstance(zorba::StoreManager::getStore());
Specification lSpec;
- int flags = zorba::file::CONVERT_SLASHES | zorba::file::RESOLVE;
std::string srcDir = zorba::UPDATE_SRC_DIR;
std::string binDir = zorba::UPDATE_BINARY_DIR;
@@ -240,28 +239,33 @@
std::string argString = std::string(argv[1]);
std::string lSpecNoSuffix = argString.substr(0, argString.size()-5);
- std::string lSpecFileString = srcDir + "/Queries/" + argv[1];
- zorba::file lSpecFile(lSpecFileString, flags);
- zorba::filesystem_path lSpecPath(lSpecFile.branch_path());
+ std::string lSpecFile( srcDir );
+ zorba::fs::append( lSpecFile, "Queries" );
+ zorba::fs::append( lSpecFile, argv[1] );
+ std::string lSpecPath( zorba::fs::dir_name( lSpecFile ) );
- if ( (! lSpecFile.exists ()) || lSpecFile.is_directory () )
+ if ( zorba::fs::get_type( lSpecFile ) != zorba::fs::file )
{
- std::cout << "\n spec file " << lSpecFile.get_path()
+ std::cout << "\n spec file " << lSpecFile
<< " does not exist or is not a file" << std::endl;
return 2;
}
std::cout << "test " << lSpecNoSuffix << std::endl;
- std::string lResultFileString = binDir+"/QueryResults/"+lSpecNoSuffix+".res";
- zorba::file lResultFile(lResultFileString, flags);
+ std::string lResultFile( binDir );
+ zorba::fs::append( lResultFile, "QueryResults" );
+ zorba::fs::append( lResultFile, lSpecNoSuffix );
+ lResultFile += ".res";
- std::string lRefFileString = srcDir+"/ExpectedTestResults/"+lSpecNoSuffix+".xml.res";
- zorba::file lRefFile(lRefFileString, flags);
- zorba::filesystem_path lRefPath(lRefFile.branch_path());
+ std::string lRefFile( srcDir );
+ zorba::fs::append( lRefFile, "ExpectedTestResults" );
+ zorba::fs::append( lRefFile, lSpecNoSuffix );
+ lRefFile += ".xml.res";
+ std::string lRefPath( zorba::fs::dir_name( lRefFile ) );
// read the xargs and errors if the spec file exists
- lSpec.parseFile(lSpecFile.get_path());
+ lSpec.parseFile(lSpecFile);
Zorba_SerializerOptions lSerOptions;
lSerOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
@@ -283,16 +287,15 @@
// Open the query file
//
std::string qname_str;
- if(lSpecPath.get_path().find("XQueryX") == std::string::npos)
+ if(lSpecPath.find("XQueryX") == std::string::npos)
qname_str = lState->theName + ".xq";
else
qname_str = lState->theName + ".xqx";
std::cout << "query name = " << qname_str << std::endl;
- zorba::filesystem_path lQueryName(qname_str,
- zorba::file::CONVERT_SLASHES);
- zorba::filesystem_path lQueryFile(lSpecPath, lQueryName);
+ std::string lQueryFile(lSpecPath);
+ zorba::fs::append( lQueryFile, qname_str );
std::cout << std::endl << "Query (Run " << curQuery+1 << "):" << std::endl;
std::cout << "Query file " << lQueryFile << ": " << std::endl;
@@ -307,7 +310,7 @@
try
{
zorba::StaticContext_t lContext = engine->createStaticContext();
- std::string path = lQueryFile.get_path();
+ std::string path = lQueryFile;
if (path.find("w3c_update_testsuite") != std::string::npos)
{
@@ -329,8 +332,8 @@
lContext->setBoundarySpacePolicy(zorba::preserve_space);
#endif
#if 1
- zorba::String lProlog = zorba::String(std::string("import schema 'http://www.w3.org/XML/1998/namespace';\n"));
-
+ zorba::String lProlog = zorba::String(std::string("import schema 'http://www.w3.org/XML/1998/namespace';\n"));
+
lContext->loadProlog(lProlog, getCompilerHints());
#endif
}
@@ -341,7 +344,7 @@
#ifdef ZORBA_TEST_PLAN_SERIALIZATION
int save_retval;
- if((save_retval = save_load_plan(engine, lQuery, smapper.get(), lResultFile.get_path())))
+ if((save_retval = save_load_plan(engine, lQuery, smapper.get(), lResultFile)))
{
return save_retval;
}
@@ -410,10 +413,9 @@
//
try
{
- if (lResultFile.exists())
- lResultFile.remove();
+ zorba::fs::remove( lResultFile, true );
- std::ofstream lResFileStream(lResultFile.get_path().c_str());
+ std::ofstream lResFileStream(lResultFile.c_str());
lQuery->execute(lResFileStream, &lSerOptions);
lResFileStream.flush();
@@ -429,24 +431,23 @@
// the ref file is the same for xqueryx and xquery tests
// hence, we remove the string xqueryx or xquery from the path
- size_t lPosOfW3C = lRefPath.get_path().find("w3c_update_testsuite");
+ size_t lPosOfW3C = lRefPath.find("w3c_update_testsuite");
if (lPosOfW3C != std::string::npos)
{
- if (lRefPath.get_path().find("XQueryX", lPosOfW3C) != std::string::npos)
+ if (lRefPath.find("XQueryX", lPosOfW3C) != std::string::npos)
lRefFileTmpString = lRefFileTmpString.erase(lPosOfW3C + 21, 8);
else
lRefFileTmpString = lRefFileTmpString.erase(lPosOfW3C + 21, 7);
}
- zorba::filesystem_path lRefFile(lRefFileTmpString,
- zorba::filesystem_path(lState->theCompares[i],
- zorba::file::CONVERT_SLASHES));
- std::cout << std::endl << "Ref " << lRefFile.get_path() << std::endl;
+ std::string lRefFile( lRefFileTmpString );
+ zorba::fs::append( lRefFile, lState->theCompares[i] );
+ std::cout << std::endl << "Ref " << lRefFile << std::endl;
int lLine, lCol;
std::string lRefLine, lResultLine;
- lRes = zorba::fileEquals(lRefFile.get_path().c_str(),
- lResultFile.get_path().c_str(),
+ lRes = zorba::fileEquals(lRefFile.c_str(),
+ lResultFile.c_str(),
lLine, lCol, lRefLine, lResultLine);
// if the simple comparison doesn't work, we do the full-fledged
@@ -464,22 +465,22 @@
std::cout << std::endl;
std::cout << "Actual and Reference results are not identical"
<< std::endl << std::endl
- << "Actual Result " << lResultFile.get_path() << ": "
- << std::endl << std::endl;
-
- zorba::printFile(std::cout, lResultFile.get_path());
-
- std::cout << std::endl << "Reference Result " << lRefFile.get_path() << ": "
- << std::endl << std::endl;
-
- zorba::printFile(std::cout, lRefFile.get_path());
+ << "Actual Result " << lResultFile << ": "
+ << std::endl << std::endl;
+
+ zorba::printFile(std::cout, lResultFile);
+
+ std::cout << std::endl << "Reference Result " << lRefFile << ": "
+ << std::endl << std::endl;
+
+ zorba::printFile(std::cout, lRefFile);
std::cout << std::endl << std::endl;
int lCanonicalRes =
zorba::canonicalizeAndCompare(State::compareTypeStr(lState->theCompareTypes[i]),
- lRefFile.get_path().c_str(),
- lResultFile.get_path().c_str());
+ lRefFile.c_str(),
+ lResultFile.c_str());
if (lCanonicalRes == 0)
{
anyMatch = true;
@@ -504,7 +505,7 @@
std::cout << std::endl;
std::cout << "Query returns result but no expected result defined!"
<< std::endl;
- zorba::printFile(std::cout, lResultFile.get_path());
+ zorba::printFile(std::cout, lResultFile);
}
}
catch (zorba::ZorbaException &e)
@@ -528,3 +529,4 @@
std::cout << "updtestdriver: success" << std::endl;
return 0;
}
+/* vim:set et sw=2 ts=2: */
=== modified file 'test/unit/CMakeLists.txt'
--- test/unit/CMakeLists.txt 2013-05-16 08:22:46 +0000
+++ test/unit/CMakeLists.txt 2013-06-03 23:16:28 +0000
@@ -77,7 +77,6 @@
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/schema1.xsd ${CMAKE_CURRENT_BINARY_DIR}/schema1.xsd)
SET(UNIT_TESTS_SRCS
- path_resolver.cpp
multiple_runs.cpp
plan_serializer.cpp
call_stack.cpp
@@ -98,7 +97,6 @@
xmldatamanager.cpp
staticcollectionmanager.cpp
test_static_context.cpp
- test_filesystempath.cpp
)
# multithread_simple.cpp
=== removed file 'test/unit/path_resolver.cpp'
--- test/unit/path_resolver.cpp 2013-02-07 17:24:36 +0000
+++ test/unit/path_resolver.cpp 1970-01-01 00:00:00 +0000
@@ -1,68 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <zorba/util/path.h>
-#include <iostream>
-
-using namespace zorba;
-using namespace std;
-
-// Test cases are here as an array of arrays. Each case comprises
-// three Strings: the input path; the base (for relative paths); and
-// the expected result.
-
-#ifdef WIN32
-
-std::string path_resolver_tests[][3] = {
- { "C:\\path\\to\\file.xx", "", "C:\\path\\to\\file.xx" },
- { "path\\to\\file.xx", "C:\\base", "C:\\base\\path\\to\\file.xx" },
- { "file:///C:/path/to/file.xx", "", "C:\\path\\to\\file.xx" },
- { "file://localhost/C:/path/to/file.xx", "", "C:\\path\\to\\file.xx" },
- { "C:/path/to//file.xx", "", "C:\\path\\to\\file.xx" }
-};
-
-#define NUM_PATH_RESOLVER_TESTS 5
-
-#else /* WIN32 */
-
-std::string path_resolver_tests[][3] = {
- { "/path/to/file.xx", "", "/path/to/file.xx" },
- { "path/to/file.xx", "/base", "/base/path/to/file.xx" },
- { "file:///path/to/file.xx", "", "/path/to/file.xx" },
- { "file://localhost/path/to/file.xx", "", "/path/to/file.xx" },
- { "\\path\\to\\\\file.xx", "", "/path/to/file.xx" }
-};
-
-#define NUM_PATH_RESOLVER_TESTS 5
-
-#endif /* WIN32 */
-
-/**
- * "main"
- */
-int path_resolver(int argc, char* argv[]) {
- for (int i = 0; i < NUM_PATH_RESOLVER_TESTS; i++) {
- std::string const *const testcase = path_resolver_tests[i];
- std::string res = filesystem_path::normalize_path(testcase[0], testcase[1]);
- if (res != testcase[2]) {
- cout << "Path resolver test " << i << " failed: expected '"
- << testcase[2] << "' but got '" << res << "'" << endl;
- return 1;
- }
- }
- return 0;
-}
-/* vim:set et sw=2 ts=2: */
=== removed file 'test/unit/test_filesystempath.cpp'
--- test/unit/test_filesystempath.cpp 2013-05-14 09:59:59 +0000
+++ test/unit/test_filesystempath.cpp 1970-01-01 00:00:00 +0000
@@ -1,80 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <iostream>
-#include <string.h>
-
-#include <zorba/store_manager.h>
-#include <zorba/zorba.h>
-#include <zorba/util/path.h>
-
-using namespace std;
-using namespace zorba;
-
-std::string filesystempath_branch_tests[][2] = {
- { "/d1/d2/../d3/.", "/d1" },
- { "/dir", "/" }
-};
-#define NUM_BRANCH_TESTS 2
-
-std::string filesystempath_path_tests[][2] = {
- { "/../d1/./././././././../..", "/" },
- { "d1/d2/../../../../d3//", "../../d3" }
-};
-#define NUM_PATH_TESTS 2
-
-int test_filesystempath (int argc, char *argv[])
-{
- bool final_success = true;
- for (int i = 0; i < NUM_BRANCH_TESTS; i++)
- {
- filesystem_path branch_test(filesystempath_branch_tests[i][0],
- filesystem_path::CONVERT_SLASHES);
- filesystem_path result = branch_test.branch_path();
- std::string result_path = result.get_path();
- //for Windows, CMake has a problem with '\' so we make an workaround
-#if defined WIN32 && !defined UNIX
- {
- string::size_type findpos = 0;
- while((findpos=result_path.find('\\', findpos)) != string::npos)
- {
- result_path.replace(findpos, 1, "/");
- }
- }
-#endif
- bool success = result_path == filesystempath_branch_tests[i][1];
- cout << "filesystem_path branch test " << i
- << (success ? " passed" : " failed") << ": expected '"
- << filesystempath_branch_tests[i][1] << " and got '"
- << result_path << "'" << endl;
- if (!success) {
- final_success = false;
- }
- }
- for (int i = 0; i < NUM_PATH_TESTS; i++) {
- std::string result_path =
- filesystem_path (filesystempath_path_tests[i][0]).get_path();
- bool success = result_path == filesystempath_path_tests[i][1];
- cout << "filesystem_path path test " << i
- << (success ? " passed" : " failed") << ": expected '"
- << filesystempath_path_tests[i][1] << " and got "
- << result_path << "'" << endl;
- if (!success) {
- final_success = false;
- }
- }
-
- return (final_success ? 0 : 1);
-}
=== modified file 'test/unit/uri_file_decoding_test.cpp'
--- test/unit/uri_file_decoding_test.cpp 2013-02-07 17:24:36 +0000
+++ test/unit/uri_file_decoding_test.cpp 2013-06-03 23:16:28 +0000
@@ -15,7 +15,7 @@
*/
#include <zorba/util/uri.h>
-#include <zorba/util/path.h>
+#include <zorba/util/fs_util.h>
#include <zorba/zorba_string.h>
using namespace zorba;
@@ -23,7 +23,7 @@
int uri_file_decoding_test(int argc, char* argv[]) {
String lTestString("file:///hello_world");
String res = URIHelper::decodeFileURI(lTestString);
- String lSep(filesystem_path::get_directory_separator());
+ String lSep(1, fs::dir_separator);
if (res != lSep.append("hello_world")) {
return 1;
Follow ups
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: noreply, 2013-06-11
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-11
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-11
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Chris Hillery, 2013-06-11
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Chris Hillery, 2013-06-11
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Chris Hillery, 2013-06-07
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-07
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-07
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-07
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-07
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-07
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Matthias Brantner, 2013-06-06
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Matthias Brantner, 2013-06-06
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-06
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-06
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-06
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-06
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-06
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Chris Hillery, 2013-06-05
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Chris Hillery, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Chris Hillery, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-05
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Chris Hillery, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-05
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-04
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-04
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-04
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-04
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-04
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-04
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-04
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-04
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-04
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-04
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-04
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-04
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-03
-
Re: [Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-03
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Zorba Build Bot, 2013-06-03
-
[Merge] lp:~zorba-coders/zorba/bug-1180220 into lp:zorba
From: Paul J. Lucas, 2013-06-03