Merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Chris Hillery
Approved revision: 11512
Merged at revision: 11504
Proposed branch: lp:~zorba-coders/zorba/bug-1180220
Merge into: lp:zorba
Diff against target: 7823 lines (+2000/-2932)
128 files modified
ChangeLog (+1/-0)
bin/path_util.cpp (+8/-8)
bin/zorbacmd.cpp (+17/-28)
include/zorba/api_shared_types.h (+60/-64)
include/zorba/base64_stream.h (+2/-1)
include/zorba/file.h (+0/-100)
include/zorba/internal/cxx_util.h (+6/-4)
include/zorba/internal/unique_ptr.h (+10/-8)
include/zorba/internal/ztd.h (+3/-1)
include/zorba/stemmer.h (+2/-1)
include/zorba/thesaurus.h (+2/-1)
include/zorba/tokenizer.h (+7/-5)
include/zorba/transcode_stream.h (+2/-1)
include/zorba/user_exception.h (+4/-3)
include/zorba/util/error_util.h (+11/-16)
include/zorba/util/file.h (+0/-122)
include/zorba/util/fs_util.h (+627/-0)
include/zorba/util/path.h (+0/-105)
include/zorba/util/stream_util.h (+48/-0)
modules/ExternalModules.conf (+10/-9)
modules/org/expath/ns/file.xq.src/file.cpp (+340/-441)
modules/org/expath/ns/file.xq.src/file.h (+8/-6)
modules/org/expath/ns/file.xq.src/file_function.cpp (+58/-87)
modules/org/expath/ns/file.xq.src/file_function.h (+4/-10)
src/api/CMakeLists.txt (+0/-5)
src/api/fileimpl.cpp (+0/-404)
src/api/fileimpl.h (+0/-94)
src/api/staticcontextimpl.cpp (+3/-3)
src/api/stemmer_wrappers.cpp (+1/-1)
src/api/thesaurus_wrappers.cpp (+1/-1)
src/api/zorba_string.cpp (+1/-1)
src/compiler/expression/ftnode.cpp (+1/-1)
src/compiler/expression/ftnode.h (+1/-2)
src/compiler/expression/ftnode_visitor.cpp (+1/-1)
src/compiler/parser/ft_types.cpp (+1/-1)
src/context/default_uri_mappers.cpp (+1/-1)
src/context/default_url_resolvers.cpp (+13/-8)
src/context/dynamic_loader.cpp (+6/-5)
src/diagnostics/assert.h (+1/-1)
src/diagnostics/diagnostic_en.xml (+0/-4)
src/diagnostics/pregenerated/dict_en.cpp (+0/-1)
src/diagnostics/pregenerated/dict_zed_keys.h (+0/-1)
src/diagnostics/user_exception.h (+1/-1)
src/diagnostics/xquery_diagnostics.h (+1/-2)
src/diagnostics/xquery_exception.cpp (+1/-1)
src/precompiled/stdafx.h (+1/-1)
src/runtime/full_text/apply.cpp (+2/-2)
src/runtime/full_text/ft_module_util.h (+3/-3)
src/runtime/full_text/ft_query_item.cpp (+2/-1)
src/runtime/full_text/ft_stop_words_set.cpp (+1/-1)
src/runtime/full_text/ft_token_matcher.cpp (+3/-3)
src/runtime/full_text/ft_token_seq_iterator.cpp (+2/-1)
src/runtime/full_text/ft_util.h (+1/-1)
src/runtime/full_text/ftcontains_visitor.cpp (+2/-1)
src/runtime/full_text/icu_tokenizer.cpp (+1/-1)
src/runtime/full_text/icu_tokenizer.h (+1/-2)
src/runtime/full_text/stemmer.cpp (+2/-1)
src/runtime/full_text/stemmer/sb_stemmer.cpp (+2/-1)
src/runtime/full_text/thesauri/encoded_list.h (+1/-1)
src/runtime/full_text/thesauri/wn_thesaurus.cpp (+8/-11)
src/runtime/full_text/thesaurus.cpp (+16/-12)
src/runtime/json/json_impl.cpp (+1/-2)
src/runtime/json/jsonml_array.cpp (+1/-1)
src/runtime/json/snelson.cpp (+1/-1)
src/runtime/util/doc_uri_heuristics.cpp (+23/-17)
src/store/naive/ft_token_store.h (+2/-1)
src/store/naive/naive_ft_token_iterator.cpp (+2/-1)
src/store/naive/store.cpp (+2/-1)
src/unit_tests/CMakeLists.txt (+2/-6)
src/unit_tests/test_ato_.cpp (+2/-1)
src/unit_tests/test_fs_iterator.cpp (+0/-54)
src/unit_tests/test_fs_util.cpp (+178/-0)
src/unit_tests/test_mem_sizeof.cpp (+2/-1)
src/unit_tests/test_string.cpp (+3/-3)
src/unit_tests/unit_test_list.h (+1/-4)
src/unit_tests/unit_tests.cpp (+1/-5)
src/util/CMakeLists.txt (+0/-1)
src/util/base64_util.h (+1/-1)
src/util/cxx_util.cpp (+2/-2)
src/util/error_util.cpp (+16/-11)
src/util/file.cpp (+0/-337)
src/util/fs_util.cpp (+232/-120)
src/util/fs_util.h (+2/-429)
src/util/fx/fxcharheap.cpp (+0/-2)
src/util/hash/hashtable.h (+2/-2)
src/util/hexbinary_util.h (+2/-1)
src/util/http_util.cpp (+6/-4)
src/util/icu_regex.cpp (+2/-1)
src/util/icu_regex.h (+2/-1)
src/util/icu_streambuf.cpp (+1/-1)
src/util/json_parser.h (+1/-1)
src/util/mem_streambuf.cpp (+2/-1)
src/util/mmap_file.cpp (+3/-2)
src/util/stl_util.h (+1/-2)
src/util/stream_util.cpp (+14/-0)
src/util/stream_util.h (+1/-1)
src/util/string/buf_rep.h (+1/-1)
src/util/string/default_rep.h (+2/-1)
src/util/string/ptr_rep.h (+2/-1)
src/util/string/rep_proxy.h (+1/-2)
src/util/string/rstring.h (+2/-1)
src/util/string_util.cpp (+2/-1)
src/util/string_util.h (+1/-1)
src/util/time_parse.cpp (+1/-1)
src/util/time_parse.h (+1/-1)
src/util/time_util.h (+1/-1)
src/util/unicode_util.cpp (+1/-1)
src/util/unordered_map.h (+2/-1)
src/util/unordered_set.h (+2/-1)
src/util/uri_util.cpp (+1/-1)
src/util/uri_util.h (+4/-2)
src/util/utf8_streambuf.cpp (+1/-1)
src/util/utf8_util.cpp (+4/-1)
src/util/utf8_util.h (+2/-1)
src/util/zorba_regex.h (+2/-1)
src/zorbatypes/URI.cpp (+0/-2)
src/zorbatypes/ft_token.cpp (+2/-1)
src/zorbatypes/ft_token.h (+1/-1)
src/zorbatypes/integer.cpp (+1/-1)
src/zorbautils/locale.cpp (+1/-1)
test/apitest.cpp (+8/-9)
test/driver/sax2testdriver.cpp (+34/-29)
test/driver/testdriver.cpp (+43/-44)
test/driver/updtestdriver.cpp (+52/-50)
test/unit/CMakeLists.txt (+0/-2)
test/unit/path_resolver.cpp (+0/-68)
test/unit/test_filesystempath.cpp (+0/-80)
test/unit/uri_file_decoding_test.cpp (+2/-2)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug-1180220
Reviewer Review Type Date Requested Status
Chris Hillery Approve
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+167177@code.launchpad.net

Commit message

Removed plethora of file classes; moved much of fs_util to the public API to take its place.

Description of the change

Removed plethora of file classes; moved much of fs_util to the public API to take its place.

To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-03T23-40-21.931Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-04T16-43-15.194Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-04T20-19-05.33Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-04T23-20-14.642Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-05T00-34-07.697Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-05T04-36-11.699Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Chris Hillery (ceejatec) wrote :

FYI, these failures keep happening after the build when it calls "make fots-import". So you should be able to test that locally.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Chris Hillery (ceejatec) wrote :

This merge proposal was timing out, which is why it kept running the RQ over and over again. (Yes, the RQ should respond more gracefully to timeouts.) I've set it to "Needs Fixing" to stop it.

The problem tests seem to be xqts-xquery and xqtsx-xqx, not too surprisingly. In particular, based on lsof output from the testdriver_mt processes, they are getting stuck in an infinite loop while executing the test Functions/AllStringFunc/MatchStringFunc/MatchesFunc/caselessmatch15. I base this on the fact that the processes in question have an open file descriptor for build/test/rbkt/QueryResults/w3c_testsuite/XQuery/Functions/AllStringFunc/MatchStringFunc/MatchesFunc/caselessmatch15.err_0 , which I think should have been closed if the testcase hadn't hung. (The xqts-xqueryx testdriver_mt process has the same file only in .../w3c_testsuite/XQueryX/....)

Looking at that test case, I can't begin to guess why it would hang with your changes, but it seems pretty consistent.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1180220 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1180220-2013-06-05T08-36-15.066Z is finished. The
  final status was:

  13 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Chris Hillery (ceejatec) wrote :

Ok, I manually killed the testdriver_mt processes on the RQ box, which allowed the last run to submit its results to CDash. So in addition to the XQTS problems, you can see there are 11 other test failures to look at.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1180220-2013-06-06T00-35-08.319Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 1 Approve.

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

What are the changes in modules/ExternalModules.conf good for?

Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

> What are the changes in modules/ExternalModules.conf good for?

Did you read Chris's only way to make incompatible changes affecting external modules e-mail? That's why. It's temporary because it's a chicken-and-egg problem.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1180220-2013-06-07T05-03-17.543Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 2 Approve, 1 Pending.

lp:~zorba-coders/zorba/bug-1180220 updated
11502. By Chris Hillery

Removed commented-out lines that only differed in removal of tags.

Revision history for this message
Chris Hillery (ceejatec) wrote :

1. What's the difference between include/zorba/internal and include/zorba/util?

2. Was it necessary/a good idea to move cxx_util.h and error_util.h into the set of shipped headers?

3. Why was cxx_util.h moved to internal/ and error_util.h to util/ ?

4. Have you done any testing on Windows? There are several #ifdef WIN32 changes. If necessary I could request Juan or Luis to test it out (would prefer Rodolfo but he's busy with website stuff).

review: Needs Information
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

> 1. What's the difference between include/zorba/internal and
> include/zorba/util?

Internal is for our use only. We make no claim that stuff in there will not either change or be removed at any time.

> 2. Was it necessary/a good idea to move cxx_util.h and error_util.h into the
> set of shipped headers?

Because they're necessary for fs_util.h.

> 3. Why was cxx_util.h moved to internal/ and error_util.h to util/ ?

Because cxx_util.h is a temporary measure until C++0x compilers are wide-spread and the file may disappear at any time; error_util.h will stick around (see #1 answer above).

> 4. Have you done any testing on Windows?

It's pretty much impossible for me to do that.

> There are several #ifdef WIN32
> changes. If necessary I could request Juan or Luis to test it out (would
> prefer Rodolfo but he's busy with website stuff).

You can, if you like.

lp:~zorba-coders/zorba/bug-1180220 updated
11503. By Paul J. Lucas

Merge from trunk.

11504. By Paul J. Lucas

Merge from trunk.

11505. By Paul J. Lucas

Merge from trunk.

11506. By Paul J. Lucas

Windows fixes.

11507. By Paul J. Lucas

Windows fix.

11508. By Paul J. Lucas

Windows fix.

11509. By Paul J. Lucas

Windows fix.

11510. By Paul J. Lucas

Merge from trunk.

11511. By Paul J. Lucas

Merge from trunk.

11512. By Paul J. Lucas

Windows fix.

Revision history for this message
Chris Hillery (ceejatec) wrote :

Juan reported some Windows compilation failures which are now fixed. There are a number of test failures but they seem to be the same set as without Paul's changes, so presumably no regressions.

review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1180220-2013-06-11T23-06-19.773Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2013-06-11 15:47:07 +0000
+++ ChangeLog 2013-06-11 16:49:27 +0000
@@ -21,6 +21,7 @@
21 * Fixed bug #1188084 (fn-replace-42 failing)21 * Fixed bug #1188084 (fn-replace-42 failing)
22 * Fixed bug in hoisting through try-catch expr22 * Fixed bug in hoisting through try-catch expr
23 * Fixed bug #1162631 (format-integer 'w' format of negative numbers)23 * Fixed bug #1162631 (format-integer 'w' format of negative numbers)
24 * Fixed bug #1180220 (Consolidate redundant path/file public APIs)
24 * Fixed bug #1103115 (Timezone units as hours are wrong)25 * Fixed bug #1103115 (Timezone units as hours are wrong)
25 * Fixed implementation of fn:deep-equal according to latest W3C spec.26 * Fixed implementation of fn:deep-equal according to latest W3C spec.
26 * Must apply document ordering on the domain expression of a FOR clause, if27 * Must apply document ordering on the domain expression of a FOR clause, if
2728
=== modified file 'bin/path_util.cpp'
--- bin/path_util.cpp 2013-02-07 17:24:36 +0000
+++ bin/path_util.cpp 2013-06-11 16:49:27 +0000
@@ -16,13 +16,13 @@
1616
17#include "path_util.h"17#include "path_util.h"
1818
19#include <stdlib.h>19#include <cstdlib>
20//#include "zorba/zorba_string.h"20
21#include "zorba/util/path.h"21#include <zorba/static_context.h>
22#include <zorba/util/fs_util.h>
2223
23#include "util.h"24#include "util.h"
24#include "zorbacmdproperties.h"25#include "zorbacmdproperties.h"
25#include <zorba/static_context.h>
2626
27namespace zorba {27namespace zorba {
2828
@@ -54,28 +54,28 @@
54 std::string lPathStr;54 std::string lPathStr;
5555
56 // Compute the current working directory to append to all paths.56 // Compute the current working directory to append to all paths.
57 filesystem_path lCWD;57 std::string lCWD( fs::curdir() );
5858
59 // setModulePaths() *overwrites* the URI path and lib path, so there's no59 // setModulePaths() *overwrites* the URI path and lib path, so there's no
60 // sense in calling both. So if --module-path exists, just use it.60 // sense in calling both. So if --module-path exists, just use it.
61 aProperties.getModulePath(lPathStr);61 aProperties.getModulePath(lPathStr);
62 if (lPathStr.length() > 0) {62 if (lPathStr.length() > 0) {
63 tokenizePath(lPathStr, lPath);63 tokenizePath(lPathStr, lPath);
64 lPath.push_back(lCWD.get_path());64 lPath.push_back(lCWD);
65 aStaticCtx->setModulePaths(lPath);65 aStaticCtx->setModulePaths(lPath);
66 }66 }
67 else {67 else {
68 // Compute and set URI path68 // Compute and set URI path
69 aProperties.getURIPath(lPathStr);69 aProperties.getURIPath(lPathStr);
70 tokenizePath(lPathStr, lPath);70 tokenizePath(lPathStr, lPath);
71 lPath.push_back(lCWD.get_path());71 lPath.push_back(lCWD);
72 aStaticCtx->setURIPath(lPath);72 aStaticCtx->setURIPath(lPath);
73 lPath.clear();73 lPath.clear();
7474
75 // Compute and set lib path75 // Compute and set lib path
76 aProperties.getLibPath(lPathStr);76 aProperties.getLibPath(lPathStr);
77 tokenizePath(lPathStr, lPath);77 tokenizePath(lPathStr, lPath);
78 lPath.push_back(lCWD.get_path());78 lPath.push_back(lCWD);
79 aStaticCtx->setLibPath(lPath);79 aStaticCtx->setLibPath(lPath);
80 }80 }
81}81}
8282
=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp 2013-05-28 00:58:27 +0000
+++ bin/zorbacmd.cpp 2013-06-11 16:49:27 +0000
@@ -30,7 +30,6 @@
30#endif30#endif
3131
32#include <zorba/zorba.h>32#include <zorba/zorba.h>
33#include <zorba/file.h>
34#include <zorba/zorba_exception.h>33#include <zorba/zorba_exception.h>
35#include <zorba/xquery_exception.h>34#include <zorba/xquery_exception.h>
36#include <zorba/document_manager.h>35#include <zorba/document_manager.h>
@@ -41,8 +40,8 @@
41#include <zorba/serialization_callback.h>40#include <zorba/serialization_callback.h>
42#include <zorba/audit.h>41#include <zorba/audit.h>
43#include <zorba/audit_scoped.h>42#include <zorba/audit_scoped.h>
44
45#include <zorba/store_manager.h>43#include <zorba/store_manager.h>
44#include <zorba/util/fs_util.h>
4645
47//#define DO_AUDIT46//#define DO_AUDIT
4847
@@ -54,9 +53,6 @@
54#include "util.h"53#include "util.h"
55#include "path_util.h"54#include "path_util.h"
5655
57// For setting the base URI from the current directory
58#include <zorba/util/path.h>
59
60// Timing utilities, including wall-clock timing56// Timing utilities, including wall-clock timing
61#include <zorba/util/time.h>57#include <zorba/util/time.h>
6258
@@ -77,8 +73,6 @@
77 "Copyright 2006-2009 The FLWOR Foundation.\n"73 "Copyright 2006-2009 The FLWOR Foundation.\n"
78 "License: Apache License 2.0: <http://www.apache.org/licenses/LICENSE-2.0>";74 "License: Apache License 2.0: <http://www.apache.org/licenses/LICENSE-2.0>";
7975
80#define PATH_SEP (zorba::filesystem_path::get_directory_separator ())
81
82#ifndef ZORBA_NO_FULL_TEXT76#ifndef ZORBA_NO_FULL_TEXT
83OneToOneURIMapper theStopWordsMapper(EntityData::STOP_WORDS);77OneToOneURIMapper theStopWordsMapper(EntityData::STOP_WORDS);
84OneToOneURIMapper theThesaurusMapper(EntityData::THESAURUS);78OneToOneURIMapper theThesaurusMapper(EntityData::THESAURUS);
@@ -368,13 +362,13 @@
368 if(str.compare(0, strlen(file3), file3) == 0) {362 if(str.compare(0, strlen(file3), file3) == 0) {
369 fpath = str.substr(strlen(file3));363 fpath = str.substr(strlen(file3));
370 } else if(str.compare(0, strlen(file2), file2) == 0) {364 } else if(str.compare(0, strlen(file2), file2) == 0) {
371 fpath = PATH_SEP;365 fpath = fs::dir_separator;
372 fpath += str.substr(strlen(file2));366 fpath += str.substr(strlen(file2));
373 }367 }
374 // replace all slash with backslash368 // replace all slash with backslash
375 std::string::size_type off=0;369 std::string::size_type off=0;
376 while ((off=fpath.find('/', off)) != std::string::npos)370 while ((off=fpath.find('/', off)) != std::string::npos)
377 fpath.replace(off, 1, PATH_SEP);371 fpath.replace(off, 1, 1, fs::dir_separator);
378 return fpath;372 return fpath;
379373
380#else // for UNIX374#else // for UNIX
@@ -639,14 +633,8 @@
639removeOutputFileIfNeeded(const ZorbaCMDProperties& lProperties)633removeOutputFileIfNeeded(const ZorbaCMDProperties& lProperties)
640{634{
641#ifdef ZORBA_WITH_FILE_ACCESS635#ifdef ZORBA_WITH_FILE_ACCESS
642 if (lProperties.outputFile().size() > 0)636 if ( !lProperties.outputFile().empty() )
643 {637 fs::remove( lProperties.outputFile(), true );
644 File_t lFile = zorba::File::createFile(lProperties.outputFile());
645 if (lFile->exists())
646 {
647 lFile->remove();
648 }
649 }
650#endif /* ZORBA_WITH_FILE_ACCESS */638#endif /* ZORBA_WITH_FILE_ACCESS */
651}639}
652640
@@ -1021,7 +1009,7 @@
1021 std::string configJvmClassPath;1009 std::string configJvmClassPath;
1022 globaproperties->getJVMClassPath(configJvmClassPath);1010 globaproperties->getJVMClassPath(configJvmClassPath);
1023 globaproperties->setJVMClassPath(cmdJvmClassPath +1011 globaproperties->setJVMClassPath(cmdJvmClassPath +
1024 filesystem_path::get_path_separator() + configJvmClassPath);1012 fs::path_separator + configJvmClassPath);
10251013
1026 // Start the engine1014 // Start the engine
10271015
@@ -1068,14 +1056,14 @@
1068 //1056 //
1069 std::string fURI = *lIter;1057 std::string fURI = *lIter;
1070 std::string fname = parseFileURI (properties.asFiles (), fURI);1058 std::string fname = parseFileURI (properties.asFiles (), fURI);
1071 zorba::filesystem_path path (fname);1059 std::string path( fname );
1072 bool asFile = ! fname.empty ();1060 bool asFile = !fname.empty();
1073 std::auto_ptr<std::istream> qfile;1061 std::auto_ptr<std::istream> qfile;
10741062
1075 if (asFile)1063 if (asFile)
1076 {1064 {
1077 path.resolve_relative ();1065 fs::make_absolute( path );
1078 qfile.reset(new std::ifstream (path.c_str ()));1066 qfile.reset( new std::ifstream( path.c_str() ) );
1079 }1067 }
1080 else1068 else
1081 {1069 {
@@ -1129,10 +1117,11 @@
1129 {1117 {
1130 // No user set base URI. Set the cwd to be used as base-uri in order1118 // No user set base URI. Set the cwd to be used as base-uri in order
1131 // to make the doc function doc("mydoc.xml") work1119 // to make the doc function doc("mydoc.xml") work
1132 zorba::filesystem_path p;1120 std::string p( fs::curdir() );
1133 std::stringstream lTmp;1121 std::stringstream lTmp;
1134 std::vector<std::string> lTokens;1122 std::vector<std::string> lTokens;
1135 Util::tokenize(p.c_str(), PATH_SEP, lTokens);1123 std::string const delim( 1, fs::dir_separator );
1124 Util::tokenize(p.c_str(), delim, lTokens);
11361125
1137 lTmp << "file://";1126 lTmp << "file://";
1138 for (std::vector<std::string>::const_iterator lIter = lTokens.begin();1127 for (std::vector<std::string>::const_iterator lIter = lTokens.begin();
@@ -1155,7 +1144,7 @@
1155 zorba::XQuery_t lQuery = lZorbaInstance->createQuery();1144 zorba::XQuery_t lQuery = lZorbaInstance->createQuery();
1156 if (asFile)1145 if (asFile)
1157 {1146 {
1158 lQuery->setFileName(path.get_path());1147 lQuery->setFileName(path);
1159 }1148 }
11601149
1161 lQuery->parse (*qfile);1150 lQuery->parse (*qfile);
@@ -1178,7 +1167,7 @@
1178 zorba::XQuery_t aQuery = lZorbaInstance->createQuery();1167 zorba::XQuery_t aQuery = lZorbaInstance->createQuery();
1179 if (asFile) 1168 if (asFile)
1180 {1169 {
1181 aQuery->setFileName(path.get_path());1170 aQuery->setFileName(path);
1182 }1171 }
11831172
1184 aQuery->parse(*qfile);1173 aQuery->parse(*qfile);
@@ -1198,7 +1187,7 @@
1198 int status = compileAndExecute(lZorbaInstance,1187 int status = compileAndExecute(lZorbaInstance,
1199 properties,1188 properties,
1200 lStaticContext,1189 lStaticContext,
1201 path.get_path(),1190 path,
1202 *qfile,1191 *qfile,
1203 *lOutputStream,1192 *lOutputStream,
1204 queryTiming);1193 queryTiming);
@@ -1236,7 +1225,7 @@
1236 }1225 }
12371226
1238 std::auto_ptr<std::istream> lXQ(new std::ifstream(path.c_str()));1227 std::auto_ptr<std::istream> lXQ(new std::ifstream(path.c_str()));
1239 std::string lFileName(path.get_path());1228 std::string lFileName(path);
12401229
1241 zorba::XQuery_t lQuery;1230 zorba::XQuery_t lQuery;
12421231
12431232
=== 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-11 16:49:27 +0000
@@ -16,75 +16,71 @@
16#ifndef ZORBA_SHARED_TYPES_INCL_H16#ifndef ZORBA_SHARED_TYPES_INCL_H
17#define ZORBA_SHARED_TYPES_INCL_H17#define ZORBA_SHARED_TYPES_INCL_H
1818
19#include <memory>
20
21#include <zorba/config.h>19#include <zorba/config.h>
22#include <zorba/smart_ptr.h>20#include <zorba/smart_ptr.h>
2321
24namespace zorba {22namespace zorba {
2523
26 class Zorba;24///////////////////////////////////////////////////////////////////////////////
27 class XQuery;25
28 class StaticContext;26class Annotation;
29 class DynamicContext;27class Collection;
30 class XmlDataManager;28class CollectionManager;
31 class DocumentManager;29class DiagnosticHandler;
32 class CollectionManager;30class DocumentManager;
33 class StaticCollectionManager;31class DynamicContext;
34 class ItemFactory;32class ExternalFunctionParameter;
35 class Iterator;33class ExternalModule;
36 class StatelessExternalFunction;34class Function;
37 class ExternalFunctionParameter;35class ItemFactory;
38 class ExternalModule;36class ItemSequence;
39 class TypeIdentifier;37class Iterator;
40 class ItemSequence;38class ModuleInfo;
41 class Collection;39class QueryLocation;
42 class Function;40class SerializationCallback;
43 class Annotation;41class Serializer;
44 class SerializationCallback;42class StatelessExternalFunction;
45 class File;43class StaticCollectionManager;
46 class DirectoryIterator;44class StaticContext;
47 class Serializer;
48 class ModuleInfo;
49
50 class DiagnosticHandler;
51 class QueryLocation;
52 typedef SmartPtr<QueryLocation> QueryLocation_t;
53
54#ifndef ZORBA_NO_FULL_TEXT45#ifndef ZORBA_NO_FULL_TEXT
55 class StemmerProvider;46class StemmerProvider;
56 class TokenizerProvider;47class TokenizerProvider;
57#endif /* ZORBA_NO_FULL_TEXT */48#endif /* ZORBA_NO_FULL_TEXT */
5849class TypeIdentifier;
59 // smart pointers50class XmlDataManager;
60 typedef zorba::SmartPtr<XQuery> XQuery_t;51class XQuery;
61 typedef zorba::SmartPtr<StaticContext> StaticContext_t;52class Zorba;
62 typedef zorba::SmartPtr<Iterator> Iterator_t;53
63 typedef zorba::SmartPtr<TypeIdentifier> TypeIdentifier_t;54// smart pointers
64 typedef zorba::SmartPtr<Collection> Collection_t;55typedef SmartPtr<Annotation> Annotation_t;
65 typedef zorba::SmartPtr<Function> Function_t;56typedef SmartPtr<Collection> Collection_t;
66 typedef zorba::SmartPtr<Annotation> Annotation_t;57typedef SmartPtr<Function> Function_t;
67 typedef zorba::SmartPtr<File> File_t;58typedef SmartPtr<ItemSequence> ItemSequence_t;
68 typedef zorba::SmartPtr<DirectoryIterator> DirectoryIterator_t;59typedef SmartPtr<Iterator> Iterator_t;
69 typedef zorba::SmartPtr<Serializer> Serializer_t;60typedef SmartPtr<ModuleInfo> ModuleInfo_t;
70 typedef zorba::SmartPtr<ItemSequence> ItemSequence_t;61typedef SmartPtr<QueryLocation> QueryLocation_t;
71 typedef zorba::SmartPtr<ModuleInfo> ModuleInfo_t;62typedef SmartPtr<Serializer> Serializer_t;
7263typedef SmartPtr<StaticContext> StaticContext_t;
73 // data handlers64typedef SmartPtr<TypeIdentifier> TypeIdentifier_t;
74 class Item;65typedef SmartPtr<XQuery> XQuery_t;
75 class String;66
7667// data handlers
77 // uri resolvers68class Item;
78 class URIMapper;69class String;
79 class Resource;70
80 class URLResolver;71// uri resolvers
8172class URIMapper;
82 namespace audit {73class Resource;
83 class Provider;74class URLResolver;
84 class Event;75
85 class ScopedRecord;76namespace audit {
86 }77 class Provider;
8778 class Event;
88} /* namespace zorba */79 class ScopedRecord;
89#endif80}
81
82///////////////////////////////////////////////////////////////////////////////
83
84} // namespace zorba
85#endif /* ZORBA_SHARED_TYPES_INCL_H */
90/* vim:set et sw=2 ts=2: */86/* vim:set et sw=2 ts=2: */
9187
=== 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-11 16:49:27 +0000
@@ -20,6 +20,7 @@
20#include <streambuf>20#include <streambuf>
2121
22#include <zorba/config.h>22#include <zorba/config.h>
23#include <zorba/internal/cxx_util.h>
23#include <zorba/internal/streambuf.h>24#include <zorba/internal/streambuf.h>
2425
25namespace zorba {26namespace zorba {
@@ -174,7 +175,7 @@
174void detach( std::basic_ios<charT,Traits> &ios ) {175void detach( std::basic_ios<charT,Traits> &ios ) {
175 int const index = internal::base64::get_streambuf_index();176 int const index = internal::base64::get_streambuf_index();
176 if ( streambuf *const buf = static_cast<streambuf*>( ios.pword( index ) ) ) {177 if ( streambuf *const buf = static_cast<streambuf*>( ios.pword( index ) ) ) {
177 ios.pword( index ) = 0;178 ios.pword( index ) = nullptr;
178 ios.rdbuf( buf->orig_streambuf() );179 ios.rdbuf( buf->orig_streambuf() );
179 internal::dealloc_streambuf( buf );180 internal::dealloc_streambuf( buf );
180 }181 }
181182
=== 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 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef ZORBA_FILE_API_H
17#define ZORBA_FILE_API_H
18
19#include <string>
20
21#include <zorba/config.h>
22#include <zorba/api_shared_types.h>
23
24namespace zorba {
25
26 /** \brief This class is the representation of file system file.
27 *
28 * ...
29 */
30 class ZORBA_DLL_PUBLIC DirectoryIterator : public SmartObject
31 {
32 public:
33
34 virtual ~DirectoryIterator() {}
35
36 virtual bool next(std::string& aPathStr) const = 0;
37 /** \brief Rewind the file find iterator
38 */
39 virtual void reset() = 0;
40 };
41
42
43 /** \brief This class is the representation of file system file.
44 *
45 * ...
46 */
47 class ZORBA_DLL_PUBLIC File : public SmartObject
48 {
49 public: // constructors
50
51 virtual ~File() {}
52
53 static File_t createFile(const std::string& path);
54
55 static const char* getDirectorySeparator();
56
57 static const char* getPathSeparator();
58
59 public: // type, enums
60
61#ifdef WIN32
62 typedef __int64 FileSize_t;
63#else
64 typedef int64_t FileSize_t;
65#endif
66
67
68 public: // public methods
69
70 virtual const std::string getFilePath() const = 0;
71 virtual const std::string getFileUri() const = 0;
72
73 virtual bool isDirectory( bool follow_symlinks = true ) const = 0;
74 virtual bool isFile( bool follow_symlinks = true ) const = 0;
75 virtual bool isLink() const = 0;
76 virtual bool isVolume( bool follow_symlinks = true ) const = 0;
77 virtual bool isInvalid() const = 0; // deprecated
78 virtual bool exists( bool follow_symlinks = true ) const = 0;
79
80 virtual void remove() = 0;
81 virtual bool create() = 0;
82 virtual bool rename(std::string const& newpath) = 0;
83
84 virtual FileSize_t getSize() const = 0;
85
86 virtual void mkdir(bool recursive) = 0;
87
88 virtual DirectoryIterator_t files() const = 0;
89
90 virtual void openInputStream(std::ifstream& aInStream, bool binary, bool trimByteOrderMark) const = 0;
91 virtual void openOutputStream(std::ofstream& aOutStream, bool binary, bool append) const = 0;
92
93 virtual time_t lastModified() const = 0;
94
95 };
96
97} /* namespace zorba */
98
99#endif
100/* vim:set et sw=2 ts=2: */
1010
=== 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-11 16:49:27 +0000
@@ -14,8 +14,8 @@
14 * limitations under the License.14 * limitations under the License.
15 */15 */
1616
17#ifndef ZORBA_CXX_UTIL_H17#ifndef ZORBA_INTERNAL_CXX_UTIL_H
18#define ZORBA_CXX_UTIL_H18#define ZORBA_INTERNAL_CXX_UTIL_H
1919
20#include <zorba/config.h>20#include <zorba/config.h>
2121
@@ -24,6 +24,7 @@
24#ifndef ZORBA_CXX_NULLPTR24#ifndef ZORBA_CXX_NULLPTR
2525
26namespace zorba {26namespace zorba {
27namespace internal {
2728
28/**29/**
29 * A \c nullptr type.30 * A \c nullptr type.
@@ -45,6 +46,7 @@
45 void operator&() const; // whose address can't be taken46 void operator&() const; // whose address can't be taken
46};47};
4748
49} // namespace internal
48} // namespace zorba50} // namespace zorba
4951
50/**52/**
@@ -55,7 +57,7 @@
55 * Bjarne's paper has a slight performance penalty.57 * Bjarne's paper has a slight performance penalty.
56 */58 */
57ZORBA_DLL_PUBLIC59ZORBA_DLL_PUBLIC
58extern zorba::nullptr_type const zorba_nullptr;60extern zorba::internal::nullptr_type const zorba_nullptr;
5961
60#define nullptr ::zorba_nullptr62#define nullptr ::zorba_nullptr
6163
@@ -78,5 +80,5 @@
7880
79///////////////////////////////////////////////////////////////////////////////81///////////////////////////////////////////////////////////////////////////////
8082
81#endif /* ZORBA_CXX_UTIL_H */83#endif /* ZORBA_INTERNAL_CXX_UTIL_H */
82/* vim:set et sw=2 ts=2: */84/* vim:set et sw=2 ts=2: */
8385
=== 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-11 16:49:27 +0000
@@ -25,6 +25,7 @@
25#else25#else
2626
27#include <algorithm> /* for swap() */27#include <algorithm> /* for swap() */
28#include "cxx_util.h"
28#include "type_traits.h"29#include "type_traits.h"
29#include "ztd.h"30#include "ztd.h"
3031
@@ -159,7 +160,8 @@
159 */160 */
160 template<typename U>161 template<typename U>
161 default_delete( default_delete<U> const&,162 default_delete( default_delete<U> const&,
162 typename enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type* = 0 )163 typename enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type*
164 = nullptr )
163 {165 {
164 }166 }
165167
@@ -218,7 +220,7 @@
218 *220 *
219 * @param p A pointer to the object to point to, if any.221 * @param p A pointer to the object to point to, if any.
220 */222 */
221 explicit unique_ptr( pointer p = 0 ) throw() : storage_( p ) {223 explicit unique_ptr( pointer p = nullptr ) throw() : storage_( p ) {
222 }224 }
223225
224 /**226 /**
@@ -266,7 +268,7 @@
266 !ZORBA_TR1_NS::is_reference<D>::value ||268 !ZORBA_TR1_NS::is_reference<D>::value ||
267 ZORBA_TR1_NS::is_same<D,E>::value269 ZORBA_TR1_NS::is_same<D,E>::value
268 )270 )
269 >::type* = 0271 >::type* = nullptr
270 ) :272 ) :
271 storage_( p.release(), move<D>( p.get_deleter() ) )273 storage_( p.release(), move<D>( p.get_deleter() ) )
272 {274 {
@@ -374,7 +376,7 @@
374 */376 */
375 pointer release() throw() {377 pointer release() throw() {
376 pointer const temp = get();378 pointer const temp = get();
377 storage_.ptr_ = 0;379 storage_.ptr_ = nullptr;
378 return temp;380 return temp;
379 }381 }
380382
@@ -385,7 +387,7 @@
385 *387 *
386 * @param p The new pointer value, if any.388 * @param p The new pointer value, if any.
387 */389 */
388 void reset( pointer p = 0 ) throw() {390 void reset( pointer p = nullptr ) throw() {
389 if ( p != storage_.ptr_ ) {391 if ( p != storage_.ptr_ ) {
390 call_deleter();392 call_deleter();
391 storage_.ptr_ = p;393 storage_.ptr_ = p;
@@ -462,7 +464,7 @@
462 typedef T* pointer;464 typedef T* pointer;
463 typedef D deleter_type;465 typedef D deleter_type;
464466
465 explicit unique_ptr( pointer p = 0 ) throw() : storage_( p ) {467 explicit unique_ptr( pointer p = nullptr ) throw() : storage_( p ) {
466 }468 }
467469
468 unique_ptr( pointer p, deleter_reference d ) : storage_( p, d ) {470 unique_ptr( pointer p, deleter_reference d ) : storage_( p, d ) {
@@ -496,11 +498,11 @@
496498
497 pointer release() throw() {499 pointer release() throw() {
498 pointer const temp = get();500 pointer const temp = get();
499 storage_.ptr_ = 0;501 storage_.ptr_ = nullptr;
500 return temp;502 return temp;
501 }503 }
502504
503 void reset( pointer p = 0 ) throw() {505 void reset( pointer p = nullptr ) throw() {
504 if ( p != storage_.ptr_ ) {506 if ( p != storage_.ptr_ ) {
505 call_deleter();507 call_deleter();
506 storage_.ptr_ = p;508 storage_.ptr_ = p;
507509
=== 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-11 16:49:27 +0000
@@ -24,6 +24,7 @@
2424
25#include <zorba/config.h>25#include <zorba/config.h>
2626
27#include "cxx_util.h"
27#include "type_traits.h"28#include "type_traits.h"
2829
29///////////////////////////////////////////////////////////////////////////////30///////////////////////////////////////////////////////////////////////////////
@@ -210,7 +211,8 @@
210 template<typename U>211 template<typename U>
211 destroy_delete( destroy_delete<U> const&,212 destroy_delete( destroy_delete<U> const&,
212 typename213 typename
213 std::enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type* = 0 )214 std::enable_if<ZORBA_TR1_NS::is_convertible<U*,T*>::value>::type*
215 = nullptr )
214 {216 {
215 }217 }
216218
217219
=== modified file 'include/zorba/stemmer.h'
--- include/zorba/stemmer.h 2013-02-07 17:24:36 +0000
+++ include/zorba/stemmer.h 2013-06-11 16:49:27 +0000
@@ -21,6 +21,7 @@
2121
22#ifndef ZORBA_NO_FULL_TEXT22#ifndef ZORBA_NO_FULL_TEXT
2323
24#include <zorba/internal/cxx_util.h>
24#include <zorba/internal/unique_ptr.h>25#include <zorba/internal/unique_ptr.h>
25#include <zorba/internal/ztd.h>26#include <zorba/internal/ztd.h>
26#include <zorba/locale.h>27#include <zorba/locale.h>
@@ -98,7 +99,7 @@
98 * \a lang.99 * \a lang.
99 */100 */
100 virtual bool getStemmer( locale::iso639_1::type lang,101 virtual bool getStemmer( locale::iso639_1::type lang,
101 Stemmer::ptr *s = 0 ) const = 0;102 Stemmer::ptr *s = nullptr ) const = 0;
102};103};
103104
104///////////////////////////////////////////////////////////////////////////////105///////////////////////////////////////////////////////////////////////////////
105106
=== modified file 'include/zorba/thesaurus.h'
--- include/zorba/thesaurus.h 2013-02-07 17:24:36 +0000
+++ include/zorba/thesaurus.h 2013-06-11 16:49:27 +0000
@@ -21,6 +21,7 @@
2121
22#ifndef ZORBA_NO_FULL_TEXT22#ifndef ZORBA_NO_FULL_TEXT
2323
24#include <zorba/internal/cxx_util.h>
24#include <zorba/internal/unique_ptr.h>25#include <zorba/internal/unique_ptr.h>
25#include <zorba/internal/ztd.h>26#include <zorba/internal/ztd.h>
26#include <zorba/locale.h>27#include <zorba/locale.h>
@@ -128,7 +129,7 @@
128 * \a lang.129 * \a lang.
129 */130 */
130 virtual bool getThesaurus( locale::iso639_1::type lang,131 virtual bool getThesaurus( locale::iso639_1::type lang,
131 Thesaurus::ptr *t = 0 ) const = 0;132 Thesaurus::ptr *t = nullptr ) const = 0;
132};133};
133134
134///////////////////////////////////////////////////////////////////////////////135///////////////////////////////////////////////////////////////////////////////
135136
=== modified file 'include/zorba/tokenizer.h'
--- include/zorba/tokenizer.h 2013-02-07 17:24:36 +0000
+++ include/zorba/tokenizer.h 2013-06-11 16:49:27 +0000
@@ -21,9 +21,10 @@
21#include <vector>21#include <vector>
2222
23#include <zorba/config.h>23#include <zorba/config.h>
24#include <zorba/locale.h>24#include <zorba/internal/cxx_util.h>
25#include <zorba/internal/unique_ptr.h>25#include <zorba/internal/unique_ptr.h>
26#include <zorba/internal/ztd.h>26#include <zorba/internal/ztd.h>
27#include <zorba/locale.h>
2728
28namespace zorba {29namespace zorba {
2930
@@ -101,7 +102,7 @@
101 virtual void token( char const *utf8_s, size_type utf8_len,102 virtual void token( char const *utf8_s, size_type utf8_len,
102 locale::iso639_1::type lang,103 locale::iso639_1::type lang,
103 size_type token_no, size_type sent_no,104 size_type token_no, size_type sent_no,
104 size_type para_no, Item const *item = 0 ) = 0;105 size_type para_no, Item const *item = nullptr ) = 0;
105 };106 };
106107
107 /////////////////////////////////////////////////////////////////////////////108 /////////////////////////////////////////////////////////////////////////////
@@ -200,7 +201,8 @@
200 */201 */
201 virtual void tokenize_string( char const *utf8_s, size_type utf8_len,202 virtual void tokenize_string( char const *utf8_s, size_type utf8_len,
202 locale::iso639_1::type lang, bool wildcards,203 locale::iso639_1::type lang, bool wildcards,
203 Callback &callback, Item const *item = 0 ) = 0;204 Callback &callback,
205 Item const *item = nullptr ) = 0;
204206
205 /////////////////////////////////////////////////////////////////////////////207 /////////////////////////////////////////////////////////////////////////////
206208
@@ -295,8 +297,8 @@
295 * \a lang.297 * \a lang.
296 */298 */
297 virtual bool getTokenizer( locale::iso639_1::type lang,299 virtual bool getTokenizer( locale::iso639_1::type lang,
298 Tokenizer::State *state = 0,300 Tokenizer::State *state = nullptr,
299 Tokenizer::ptr *t = 0 ) const = 0;301 Tokenizer::ptr *t = nullptr ) const = 0;
300};302};
301303
302///////////////////////////////////////////////////////////////////////////////304///////////////////////////////////////////////////////////////////////////////
303305
=== 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-11 16:49:27 +0000
@@ -18,6 +18,7 @@
18#define ZORBA_TRANSCODE_STREAM_API_H18#define ZORBA_TRANSCODE_STREAM_API_H
1919
20#include <zorba/config.h>20#include <zorba/config.h>
21#include <zorba/internal/cxx_util.h>
21#include <zorba/internal/streambuf.h>22#include <zorba/internal/streambuf.h>
22#include <zorba/internal/unique_ptr.h>23#include <zorba/internal/unique_ptr.h>
2324
@@ -164,7 +165,7 @@
164void detach( std::basic_ios<charT,Traits> &ios ) {165void detach( std::basic_ios<charT,Traits> &ios ) {
165 int const index = internal::transcode::get_streambuf_index();166 int const index = internal::transcode::get_streambuf_index();
166 if ( streambuf *const buf = static_cast<streambuf*>( ios.pword( index ) ) ) {167 if ( streambuf *const buf = static_cast<streambuf*>( ios.pword( index ) ) ) {
167 ios.pword( index ) = 0;168 ios.pword( index ) = nullptr;
168 ios.rdbuf( buf->orig_streambuf() );169 ios.rdbuf( buf->orig_streambuf() );
169 internal::dealloc_streambuf( buf );170 internal::dealloc_streambuf( buf );
170 }171 }
171172
=== 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-11 16:49:27 +0000
@@ -21,6 +21,7 @@
2121
22#include <zorba/api_shared_types.h>22#include <zorba/api_shared_types.h>
23#include <zorba/error.h>23#include <zorba/error.h>
24#include <zorba/internal/cxx_util.h>
24#include <zorba/xquery_exception.h>25#include <zorba/xquery_exception.h>
2526
26namespace zorba {27namespace zorba {
@@ -60,7 +61,7 @@
60 ZorbaException::line_type raise_line,61 ZorbaException::line_type raise_line,
61 char const *ns, char const *prefix, char const *localname,62 char const *ns, char const *prefix, char const *localname,
62 char const *description, diagnostic::location const &loc,63 char const *description, diagnostic::location const &loc,
63 error_object_type *error_object = 0 );64 error_object_type *error_object = nullptr );
6465
65/**66/**
66 * \internal67 * \internal
@@ -83,7 +84,7 @@
83 ZorbaException::line_type raise_line,84 ZorbaException::line_type raise_line,
84 Error const &error, char const *description,85 Error const &error, char const *description,
85 diagnostic::location const &loc,86 diagnostic::location const &loc,
86 error_object_type *error_object = 0 );87 error_object_type *error_object = nullptr );
8788
88} // namespace internal89} // namespace internal
8990
@@ -369,7 +370,7 @@
369make_user_exception( char const *raise_file,370make_user_exception( char const *raise_file,
370 ZorbaException::line_type raise_line,371 ZorbaException::line_type raise_line,
371 Error const &error, String const &description,372 Error const &error, String const &description,
372 error_object_type *error_object = 0 );373 error_object_type *error_object = nullptr );
373374
374///////////////////////////////////////////////////////////////////////////////375///////////////////////////////////////////////////////////////////////////////
375376
376377
=== 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-11 16:49:27 +0000
@@ -15,10 +15,13 @@
15 */15 */
1616
17#pragma once17#pragma once
18#ifndef ZORBA_ERROR_UTIL_H18#ifndef ZORBA_API_ERROR_UTIL_H
19#define ZORBA_ERROR_UTIL_H19#define ZORBA_API_ERROR_UTIL_H
2020
21#include <zorba/config.h>21#include <zorba/config.h>
22#include <zorba/internal/cxx_util.h>
23#include <zorba/internal/type_traits.h>
24#include <zorba/internal/ztd.h>
2225
23#include <stdexcept>26#include <stdexcept>
24#ifndef WIN3227#ifndef WIN32
@@ -27,9 +30,6 @@
27# include <windows.h>30# include <windows.h>
28#endif /* WIN32 */31#endif /* WIN32 */
2932
30#include "cxx_util.h"
31#include "string_util.h"
32
33namespace zorba {33namespace zorba {
34namespace os_error {34namespace os_error {
3535
@@ -47,7 +47,7 @@
47 * An %exception is-a std::runtime_error for reporting errors with operating47 * An %exception is-a std::runtime_error for reporting errors with operating
48 * system or library functions.48 * system or library functions.
49 */49 */
50class exception : public std::runtime_error {50class ZORBA_DLL_PUBLIC exception : public std::runtime_error {
51public:51public:
52 /**52 /**
53 * Constructs an %exception.53 * Constructs an %exception.
@@ -60,11 +60,7 @@
60 * the operating system error string; if empty, no error string is used.60 * the operating system error string; if empty, no error string is used.
61 */61 */
62 exception( char const *function, char const *path,62 exception( char const *function, char const *path,
63 char const *err_string = nullptr ) :63 char const *err_string = nullptr );
64 std::runtime_error( make_what( function, path, err_string ) ),
65 function_( function ), path_( path )
66 {
67 }
6864
69 /**65 /**
70 * Destroys an %exception.66 * Destroys an %exception.
@@ -90,9 +86,6 @@
90 }86 }
9187
92protected:88protected:
93 static std::string make_what( char const *function, char const *path,
94 char const *err_string = nullptr );
95
96 std::string function_;89 std::string function_;
97 std::string path_;90 std::string path_;
98};91};
@@ -106,6 +99,7 @@
106 * @param err_string The error string.99 * @param err_string The error string.
107 * @return Returns said error string.100 * @return Returns said error string.
108 */101 */
102ZORBA_DLL_PUBLIC
109std::string format_err_string( char const *function, char const *err_string );103std::string format_err_string( char const *function, char const *err_string );
110104
111/**105/**
@@ -116,6 +110,7 @@
116 * @param err_string The error string.110 * @param err_string The error string.
117 * @return Returns said error string.111 * @return Returns said error string.
118 */112 */
113ZORBA_DLL_PUBLIC
119std::string format_err_string( char const *function, code_type code,114std::string format_err_string( char const *function, code_type code,
120 char const *err_string );115 char const *err_string );
121116
@@ -139,6 +134,7 @@
139 * @param code The operating system error code.134 * @param code The operating system error code.
140 * @return Returns said error string.135 * @return Returns said error string.
141 */136 */
137ZORBA_DLL_PUBLIC
142std::string get_err_string( char const *function,138std::string get_err_string( char const *function,
143 code_type code = get_err_code() );139 code_type code = get_err_code() );
144140
@@ -170,8 +166,7 @@
170166
171} // namespace os_error167} // namespace os_error
172} // namespace zorba168} // namespace zorba
173169#endif /* ZORBA_API_ERROR_UTIL_H */
174#endif /* ZORBA_ERROR_UTIL_H */
175/*170/*
176 * Local variables:171 * Local variables:
177 * mode: c++172 * mode: c++
178173
=== 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 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ZORBA_FILE_H
18#define ZORBA_FILE_H
19
20#ifndef WIN32
21#include <stdint.h>
22#endif
23
24#include <cstdio>
25#include <string>
26#include <time.h>
27#include <vector>
28
29#include <zorba/config.h>
30#include <zorba/file.h>
31#include <zorba/util/path.h>
32
33namespace zorba {
34
35class ZORBA_DLL_PUBLIC file : public filesystem_path
36{
37public:
38
39 enum filetype {
40 type_invalid,
41 type_non_existent,
42 type_directory,
43 type_link,
44 type_file,
45 type_volume,
46 type_other
47 };
48
49 typedef zorba::File::FileSize_t file_size_t;
50
51protected:
52 filetype do_stat( bool follow_symlinks = true, file_size_t *size = 0 ) const;
53
54public:
55 file(const filesystem_path &path, int flags = 0);
56
57public: // common methods
58 void set_path(std::string const& _path ) { *((filesystem_path *) this) = _path; }
59 void set_filetype(filetype) { /* do nothing */ } // deprecated
60
61 filetype get_filetype( bool follow_symlinks = true ) const {
62 return do_stat( follow_symlinks );
63 }
64
65 bool is_directory( bool follow_symlinks = true ) const {
66 return do_stat( follow_symlinks ) == type_directory;
67 }
68
69 bool is_file( bool follow_symlinks = true ) const {
70 return do_stat( follow_symlinks ) == type_file;
71 }
72
73 bool is_link() const {
74 return do_stat( false ) == type_link;
75 }
76
77 bool is_volume( bool follow_symlinks = true ) const {
78 return do_stat( follow_symlinks ) == type_volume;
79 }
80
81 bool is_invalid() const { // deprecated
82 return false;
83 }
84
85 bool exists( bool follow_symlinks = true ) const {
86 return do_stat( follow_symlinks ) != type_non_existent;
87 }
88
89 time_t lastModified() const;
90
91public: // file methods
92 void create();
93 void remove(bool ignore = true);
94 void rename(std::string const& newpath);
95
96 file_size_t get_size() const {
97 file_size_t size;
98 do_stat( true, &size );
99 return size;
100 }
101
102public: // directory methods
103 void mkdir();
104 void deep_mkdir();
105 void rmdir(bool ignore = true);
106 void lsdir(std::vector<std::string> &list);
107#ifndef _WIN32_WCE
108 void chdir();
109#endif
110
111 bool is_empty() const { return get_size() == 0; }
112};
113
114
115} // namespace zorba
116#endif /* ZORBA_FILE_H */
117/*
118 * Local variables:
119 * mode: c++
120 * End:
121 */
122/* vim:set et sw=2 ts=2: */
1230
=== 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-11 16:49:27 +0000
@@ -0,0 +1,627 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ZORBA_API_FS_UTIL_H
18#define ZORBA_API_FS_UTIL_H
19
20// standard
21#include <cctype>
22#include <iostream>
23#include <string>
24#ifdef WIN32
25# include <windows.h>
26#else
27# include <dirent.h>
28# include <sys/types.h> /* for off_t */
29#endif /* WIN32 */
30
31#ifndef MAX_PATH
32/**
33 * Maximum path length. This is defined under Windows to be 1024. There is no
34 * equivalent constant/macro for *nix systems, so simply borrow Windows' value.
35 */
36#define MAX_PATH 1024
37#endif /* MAX_PATH */
38
39// Zorba
40#include <zorba/config.h>
41#include <zorba/internal/cxx_util.h>
42#include <zorba/internal/ztd.h>
43#include <zorba/util/error_util.h>
44
45namespace zorba {
46namespace fs {
47
48////////// Exceptions /////////////////////////////////////////////////////////
49
50typedef os_error::exception exception;
51
52////////// constants //////////////////////////////////////////////////////////
53
54#ifdef WIN32
55char const dir_separator = '\\';
56char const path_separator = ';';
57#else
58char const dir_separator = '/';
59char const path_separator = ':';
60#endif /* WIN32 */
61
62////////// types //////////////////////////////////////////////////////////////
63
64/**
65 * File size type.
66 */
67#ifdef WIN32
68typedef __int64 size_type;
69#else
70typedef off_t size_type;
71#endif /* WIN32 */
72
73/**
74 * File type.
75 */
76enum type {
77 non_existent,
78 directory,
79 file,
80 link,
81 volume,
82 other // named pipe, character/block special, socket, etc.
83};
84extern char const *const type_string[];
85
86/**
87 * Emits the string representation of a file type to the given ostream.
88 *
89 * @param o The ostream to emit to.
90 * @param t The file type to emit.
91 * @return Returns \a o.
92 */
93inline std::ostream& operator<<( std::ostream &o, type t ) {
94 return o << type_string[ t ];
95}
96
97////////// Windows ////////////////////////////////////////////////////////////
98
99#ifdef WIN32
100namespace win32 {
101
102// Do not use this function directly.
103ZORBA_DLL_PUBLIC
104void make_absolute_impl( char const *path, char *abs_path );
105
106} // namespace win32
107#endif /* WIN32 */
108
109////////// Directory //////////////////////////////////////////////////////////
110
111/**
112 * Gets the current directory.
113 *
114 * @return Returns said directory.
115 * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR if it
116 * fails.
117 */
118ZORBA_DLL_PUBLIC
119std::string curdir();
120
121#ifdef ZORBA_WITH_FILE_ACCESS
122
123/**
124 * Creates a directory.
125 *
126 * @param path The full path of the directory to create.
127 * @throws fs::exception if the creation fails.
128 */
129ZORBA_DLL_PUBLIC
130void mkdir( char const *path );
131
132/**
133 * Creates a directory.
134 *
135 * @tparam PathStringType The \a path string type.
136 * @param path The full path of the directory to create.
137 * @throws fs::exception if the creation fails.
138 */
139template<class PathStringType> inline
140typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),void>::type
141mkdir( PathStringType const &path ) {
142 mkdir( path.c_str() );
143}
144
145#endif /* ZORBA_WITH_FILE_ACCESS */
146
147////////// File deletion //////////////////////////////////////////////////////
148
149#ifdef ZORBA_WITH_FILE_ACCESS
150
151/**
152 * Removes the given file or directory.
153 *
154 * @param path The full path of the file or directory to remove.
155 * @param ignore_not_found If \c true, a non-existant \a path will not throw an
156 * exception.
157 * @return Returns \c true if removal succeeds and \c false if it fails and
158 * \a ignore_not_found is \c true.
159 * @throws fs::exception if the removal fails unless \a path is non-existant
160 * and \a ignore_not_found is \c true.
161 */
162ZORBA_DLL_PUBLIC
163bool remove( char const *path, bool ignore_not_found = false );
164
165/**
166 * Removes the given file or directory.
167 *
168 * @tparam PathStringType The \a path string type.
169 * @param path The full path of the file or directory to remove.
170 * @param ignore_not_found If \c true, a non-existant \a path will not throw an
171 * exception.
172 * @return Returns \c true if removal succeeds and \c false if it fails and
173 * \a ignore_not_found is \c true.
174 * @throws fs::exception if the removal fails unless \a path is non-existant
175 * and \a ignore_not_found is \c true.
176 */
177template<class PathStringType> inline
178typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),bool>::type
179remove( PathStringType const &path, bool ignore_not_found = false ) {
180 return remove( path.c_str(), ignore_not_found );
181}
182
183#endif /* ZORBA_WITH_FILE_ACCESS */
184
185////////// File information ///////////////////////////////////////////////////
186
187/**
188 * Checks whether the given path is an absolute path.
189 *
190 * @param path The full path to check.
191 * @return Returns \c true only if the path is absolute.
192 */
193inline bool is_absolute( char const *path ) {
194#ifndef WIN32
195 return path[0] == '/';
196#else
197 //
198 // No, this should NOT also check for '/'. The path should have been
199 // normalized for Windows first, i.e., have '/' replaced by '\'.
200 //
201 return isalpha( path[0] ) && path[1] == ':' && path[2] == '\\';
202#endif /* WIN32 */
203}
204
205/**
206 * Checks whether the given path is an absolute path.
207 *
208 * @tparam PathStringType The \a path string type.
209 * @param path The full path to check.
210 * @return Returns \c true only if the path is absolute.
211 */
212template<class PathStringType> inline
213typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),bool>::type
214is_absolute( PathStringType const &path ) {
215 return is_absolute( path.c_str() );
216}
217
218/**
219 * Gets the base name of the given path name, i.e., the file name without the
220 * path leading up to it.
221 *
222 * @param path The full path to get the base name of.
223 * @return Returns the base name. Note that if \a path is just a file name,
224 * then returns \a path.
225 */
226inline char const* base_name( char const *path ) {
227 char const *const sep = ::strrchr( path, dir_separator );
228 return sep && sep[1] ? sep + 1 : path;
229}
230
231/**
232 * Gets the base name of the given path name, i.e., the file name without the
233 * path leading up to it.
234 *
235 * @tparam PathStringType The \a path string type.
236 * @param path The full path to get the base name of.
237 * @return Returns the base name. If \a path is just a file name, returns
238 * \a path.
239 */
240template<class PathStringType> inline
241typename std::enable_if<ZORBA_IS_STRING(PathStringType),PathStringType>::type
242base_name( PathStringType const &path ) {
243 typename PathStringType::size_type const pos = path.rfind( dir_separator );
244 return pos != PathStringType::npos && pos < path.size() - 1 ?
245 path.substr( pos + 1 ) : path;
246}
247
248/**
249 * Gets the directory name of the given path name, i.e., the path up to but not
250 * including the last path component.
251 *
252 * @param path The path to get the directory name of.
253 * @return Returns the direcory path. If \a path is just a file name, returns
254 * <code>'.'</code>.
255 */
256inline std::string dir_name( char const *path ) {
257 if ( char const *const sep = ::strrchr( path, dir_separator ) )
258 return sep == path ?
259 std::string( 1, dir_separator ) : std::string( path, sep );
260 return std::string( 1, '.' );
261}
262
263/**
264 * Gets the directory name of the given path name, i.e., the path up to but not
265 * including the last path component.
266 *
267 * @tparam PathStringType The \a path string type.
268 * @param path The path to get the directory name of.
269 * @return Returns the direcory path. If \a path is just a file name, returns
270 * <code>'.'</code>.
271 */
272template<class PathStringType> inline
273typename std::enable_if<ZORBA_IS_STRING(PathStringType),PathStringType>::type
274dir_name( PathStringType const &path ) {
275 typename PathStringType::size_type const pos = path.rfind( dir_separator );
276 if ( pos == PathStringType::npos )
277 return PathStringType( 1, '.' );
278 if ( pos == 0 ) // e.g., /foo
279 return PathStringType( 1, dir_separator );
280#ifdef WIN32
281 if ( pos == 2 && is_absolute( path ) )
282 return path.substr( 0, 3 );
283#endif /* WIN32 */
284 return path.substr( 0, pos );
285}
286
287#ifdef ZORBA_WITH_FILE_ACCESS
288
289/**
290 * File information for use with get_type().
291 */
292struct info {
293 time_t mtime; ///< file's last modification time (in seconds since epoch)
294 size_type size; ///< file's size in bytes
295 fs::type type; ///< file's type
296};
297
298/**
299 * Gets the type of the given file.
300 *
301 * @param path The full path to check.
302 * @param follow_symlink If \c true, follows symbolic links.
303 * @param pinfo A pointer to a receive file information, or \c null.
304 * @return If \a path refers to a symbolic link and \a follow_symlink is
305 * \c true, the type returned is of that to which the link refers; if \a path
306 * refers to a symbolic and \a follow_symlink is \c false, returns \c link; if
307 * \a path does not refer to a symbolic link, returns the type of \a path.
308 * @throws fs::exception for typical failures (file not found, invalid path,
309 * permission denied, etc).
310 * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
311 * unrecoverable failures.
312 */
313ZORBA_DLL_PUBLIC
314type get_type( char const *path, bool follow_symlink, info *pinfo = nullptr );
315
316/**
317 * Gets the type of the given file.
318 *
319 * @param path The full path to check.
320 * @param pinfo A pointer to a receive file information, or \c null.
321 * @return If \a path refers to a symbolic link, the type returned is of that
322 * to which the link refers; if \a path does not refer to a symbolic link,
323 * returns the type of \a path.
324 * @throws fs::exception for typical failures (file not found, invalid path,
325 * permission denied, etc).
326 * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
327 * unrecoverable failures.
328 */
329inline type get_type( char const *path, info *pinfo = nullptr ) {
330 return get_type( path, true, pinfo );
331}
332
333/**
334 * Gets the type of the given file.
335 *
336 * @tparam PathStringType The \a path string type.
337 * @param path The full path to check.
338 * @param follow_symlink If \c true, follows symbolic links.
339 * @param pinfo A pointer to a receive file information, or \c null.
340 * @return If \a path refers to a symbolic link and \a follow_symlink is
341 * \c true, the type returned is of that to which the link refers; if \a path
342 * refers to a symbolic and \a follow_symlink is \c false, returns \c link; if
343 * \a path does not refer to a symbolic link, returns the type of \a path.
344 * @throws fs::exception for typical failures (file not found, invalid path,
345 * permission denied, etc).
346 * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
347 * unrecoverable failures.
348 */
349template<class PathStringType> inline
350typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),type>::type
351get_type( PathStringType const &path, bool follow_symlink,
352 info *pinfo = nullptr ) {
353 return get_type( path.c_str(), follow_symlink, pinfo );
354}
355
356/**
357 * Gets the type of the given file.
358 *
359 * @tparam PathStringType The \a path string type.
360 * @param path The full path to check.
361 * @param pinfo A pointer to a receive file information, or \c null.
362 * @return If \a path refers to a symbolic link, the type returned is of that
363 * to which the link refers; if \a path does not refer to a symbolic link,
364 * returns the type of \a path.
365 * @throws fs::exception for typical failures (file not found, invalid path,
366 * permission denied, etc).
367 * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR for
368 * unrecoverable failures.
369 */
370template<class PathStringType> inline
371typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),type>::type
372get_type( PathStringType const &path, info *pinfo = nullptr ) {
373 return get_type( path.c_str(), pinfo );
374}
375
376#endif /* ZORBA_WITH_FILE_ACCESS */
377
378////////// Directory iteration ////////////////////////////////////////////////
379
380#ifdef ZORBA_WITH_FILE_ACCESS
381
382/**
383 * An %fs::iterator iterates over the entries in a directory.
384 */
385class ZORBA_DLL_PUBLIC iterator {
386public:
387 /**
388 * Information for a directory entry.
389 */
390 struct entry {
391 char const *name;
392 fs::type type;
393 };
394
395 /**
396 * Constructs an %iterator.
397 *
398 * @param path The full path to the directory to iterate over.
399 * @throws fs::exception if the construction failed, e.g., path not found.
400 */
401 iterator( char const *path ) : dir_path_( path ) {
402 ctor_impl();
403 }
404
405 /**
406 * Constructs an %iterator.
407 *
408 * @tparam PathStringType The \a path string type.
409 * @param path The full path to the directory to iterate over.
410 * @throws fs::exception if the construction failed, e.g., path not found.
411 */
412 template<class PathStringType>
413 iterator( PathStringType const &path,
414 typename std::enable_if<ZORBA_HAS_C_STR(PathStringType)
415 >::type* = 0 ) : dir_path_( path.c_str() ) {
416 ctor_impl();
417 }
418
419 /**
420 * Destroys this %iterator.
421 */
422 ~iterator();
423
424 /**
425 * Attempts to get the next directory entry.
426 *
427 * @return Returns \c true only if there is a next directory.
428 */
429 bool next();
430
431 /**
432 * Gets the current directory entry. The entry is undefined unless next()
433 * returned \c true.
434 *
435 * @return Returns said entry.
436 */
437 entry const& operator*() const {
438 return entry_;
439 }
440
441 /**
442 * Gets the current directory entry. The entry is undefined unless next()
443 * returned \c true.
444 *
445 * @return Returns said entry.
446 */
447 entry const* operator->() const {
448 return &entry_;
449 }
450
451 /**
452 * Gets the directory's path.
453 *
454 * @return Returns said path.
455 */
456 char const* path() const {
457 return dir_path_.c_str();
458 }
459
460 /**
461 * Resets this iterator to the beginning.
462 */
463 void reset();
464
465private:
466 std::string dir_path_;
467 entry entry_;
468#ifndef WIN32
469 DIR *dir_;
470#else
471 HANDLE dir_;
472 bool dir_is_empty_;
473 WIN32_FIND_DATA ent_data_;
474 char entry_name_buf_[ MAX_PATH ];
475 bool use_first_;
476
477 void win32_opendir( char const *path );
478 void win32_closedir();
479#endif /* WIN32 */
480
481 void ctor_impl();
482
483 // forbid
484 iterator( iterator const& );
485 iterator& operator=( iterator const& );
486};
487
488#endif /* ZORBA_WITH_FILE_ACCESS */
489
490////////// Path normalization /////////////////////////////////////////////////
491
492/**
493 * Gets the normalized path of the given path. A normalized path is one that:
494 * - has \c file:// URIs converted to paths
495 * - has directory separators corrected for the host operating system
496 * - has adjacent directory separators combined, e.g., \c /a//b becomes \c /a/b
497 * - has \c ./ removed, e.g., \c /a/./b becomes \c /a/b
498 * - has \c ../ removed, e.g., \c /a/b/../c becomes \c /a/c
499 *
500 * @param path The path to normalize.
501 * @param base The base path. If not empty, is prepended to \a path.
502 * @return Returns the normalized path.
503 * @throws std::invalid_argument for malformed paths.
504 */
505ZORBA_DLL_PUBLIC
506std::string normalize_path( char const *path, char const *base = nullptr );
507
508/**
509 * Gets the normalized path of the given path. A normalized path is one that:
510 * - has \c file:// URIs converted to paths
511 * - has directory separators corrected for the host operating system
512 * - has adjacent directory separators combined, e.g., \c /a//b becomes \c /a/b
513 * - has \c ./ removed, e.g., \c /a/./b becomes \c /a/b
514 * - has \c ../ removed, e.g., \c /a/b/../c becomes \c /a/c
515 *
516 * @tparam PathStringType The \a path string type.
517 * @param path The path to normalize.
518 * @return Returns the normalized path.
519 * @throws std::invalid_argument for malformed paths.
520 */
521template<class PathStringType> inline
522typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),std::string>::type
523normalize_path( PathStringType const &path ) {
524 return normalize_path( path.c_str() );
525}
526
527/**
528 * Gets the normalized path of the given path. A normalized path is one that:
529 * - has \c file:// URIs converted to paths
530 * - has directory separators corrected for the host operating system
531 * - has adjacent directory separators combined, e.g., \c /a//b becomes \c /a/b
532 * - has \c ./ removed, e.g., \c /a/./b becomes \c /a/b
533 * - has \c ../ removed, e.g., \c /a/b/../c becomes \c /a/c
534 *
535 * @tparam PathStringType The \a path string type.
536 * @tparam BaseStringType The \a base string type.
537 * @param path The path to normalize.
538 * @param base The base path. If not empty, is prepended to \a path.
539 * @return Returns the normalized path.
540 * @throws std::invalid_argument for malformed paths.
541 */
542template<class PathStringType,class BaseStringType> inline
543typename std::enable_if<ZORBA_HAS_C_STR(PathStringType)
544 && ZORBA_HAS_C_STR(BaseStringType),
545 std::string>::type
546normalize_path( PathStringType const &path, BaseStringType const &base ) {
547 return normalize_path( path.c_str(), base.c_str() );
548}
549
550////////// Path manipulation //////////////////////////////////////////////////
551
552/**
553 * Appends a path component onto another path ensuring that exactly one
554 * separator is used.
555 *
556 * @tparam PathStringType1 The \a path1 string type.
557 * @param path1 The path to append to.
558 * @param path2 The path to append.
559 */
560template<class PathStringType1> inline
561typename std::enable_if<ZORBA_IS_STRING(PathStringType1),void>::type
562append( PathStringType1 &path1, char const *path2 ) {
563 if ( !path1.empty() && path1[ path1.size() - 1 ] != dir_separator
564 && path2[0] != dir_separator ) {
565 path1 += dir_separator;
566 }
567 path1 += path2;
568}
569
570/**
571 * Appends a path component onto another path.
572 *
573 * @tparam PathStringType1 The \a path1 string type.
574 * @tparam PathStringType2 The \a path2 string type.
575 * @param path1 The path to append to.
576 * @param path2 The path to append.
577 */
578template<class PathStringType1,class PathStringType2> inline
579typename std::enable_if<ZORBA_IS_STRING(PathStringType1)
580 && ZORBA_HAS_C_STR(PathStringType2),
581 void>::type
582append( PathStringType1 &path1, PathStringType2 const &path2 ) {
583 append( path1, path2.c_str() );
584}
585
586/**
587 * Makes a relative path into an absolute path.
588 *
589 * @param path The path to make absolute. It is assumes that the buffer to
590 * which \a path points is at least MAX_PATH bytes.
591 */
592ZORBA_DLL_PUBLIC
593void make_absolute( char *path );
594
595/**
596 * Makes a relative path into an absolute path.
597 *
598 * @tparam PathStringType The \a path string type.
599 * @param path The path to make absolute.
600 */
601template<class PathStringType> inline
602typename std::enable_if<ZORBA_IS_STRING(PathStringType),void>::type
603make_absolute( PathStringType &path ) {
604 if ( !is_absolute( path ) ) {
605#ifndef WIN32
606 typedef typename PathStringType::size_type size_type;
607 path.insert( static_cast<size_type>(0), 1, '/' );
608 path.insert( 0, curdir().c_str() );
609#else
610 char temp[ MAX_PATH ];
611 win32::make_absolute_impl( path.c_str(), temp );
612 path = temp;
613#endif /* WIN32 */
614 }
615}
616
617///////////////////////////////////////////////////////////////////////////////
618
619} // namespace fs
620} // namespace zorba
621#endif /* ZORBA_API_FS_UTIL_H */
622/*
623* Local variables:
624* mode: c++
625* End:
626*/
627/* vim:set et sw=2 ts=2: */
0628
=== 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 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ZORBA_PATH_H
18#define ZORBA_PATH_H
19
20#include <string>
21#include <iostream>
22#include <zorba/config.h>
23
24namespace zorba {
25
26class ZORBA_DLL_PUBLIC filesystem_path {
27private:
28 std::string path;
29
30 void canonicalize ();
31
32protected:
33 std::string
34 getPathString() const;
35
36public:
37 enum flags_t {
38 CONVERT_SLASHES = 1,
39 RESOLVE = 2
40 };
41
42public:
43
44 /**
45 * @brief Utility function to normalize a path as a system conforming
46 * path and optionally resolve it.
47 *
48 * This function takes a path (as system path, file uri) and normalizes it.
49 * It converts file URIs to system paths and replaces '/' and '\' to the
50 * platform specific directory separator ('\' on Windows, '/' on UNIX like
51 * operating systems like Linux and Mac OS X).
52 * If the parameter base is set, it also resolves the path.
53 *
54 * @param in The path to normalize.
55 * @param base The base name to resolve a path (default = ""), if this is the
56 * empty string, it does not resolve anything, but only normalizes
57 * the path.
58 * @return Returns a normalized and optionally a resolved path.
59 */
60 static std::string normalize_path(std::string const &in, std::string const &base = "");
61
62 // from current dir
63 filesystem_path ();
64
65 filesystem_path (const std::string &path_, int flags = 0);
66
67 filesystem_path (const filesystem_path &base, const filesystem_path &rel) {
68 if (rel.is_complete ())
69 *this = rel;
70 else {
71 *this = base.get_path () + get_directory_separator () + rel.get_path ();
72 canonicalize ();
73 }
74 }
75
76 filesystem_path &operator = (const std::string &p_)
77 { path = p_; canonicalize (); return *this; }
78
79 const std::string &get_path () const { return path; }
80 const char *c_str () const { return path.c_str (); }
81 operator const std::string & () const { return path; }
82
83 bool is_complete () const;
84 bool is_root () const;
85 void resolve_relative ();
86
87 filesystem_path branch_path () const;
88
89 static const char *get_directory_separator ();
90 static const char *get_path_separator ();
91};
92
93inline std::ostream &operator<< (std::ostream &os, const filesystem_path &p) {
94 return os << p.get_path ();
95}
96
97
98} // namespace zorba
99#endif /* ZORBA_PATH_H */
100/*
101* Local variables:
102* mode: c++
103* End:
104*/
105/* vim:set et sw=2 ts=2: */
1060
=== 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-11 16:49:27 +0000
@@ -0,0 +1,48 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18#ifndef ZORBA_API_STREAM_UTIL_H
19#define ZORBA_API_STREAM_UTIL_H
20
21#include <iostream>
22
23#include <zorba/config.h>
24
25namespace zorba {
26
27///////////////////////////////////////////////////////////////////////////////
28
29/**
30 * Skips the UTF-8 byte order mark (BOM), if any.
31 *
32 * @param is The istream to read.
33 * @return Returns \c true only if a BOM was present and skipped.
34 */
35ZORBA_DLL_PUBLIC
36bool skip_utf8_bom( std::istream &is );
37
38///////////////////////////////////////////////////////////////////////////////
39
40} // namespace zorba
41
42#endif /* ZORBA_API_STREAM_UTIL_H */
43/*
44 * Local variables:
45 * mode: c++
46 * End:
47 */
48/* vim:set et sw=2 ts=2: */
049
=== modified file 'modules/ExternalModules.conf'
--- modules/ExternalModules.conf 2013-05-29 00:52:05 +0000
+++ modules/ExternalModules.conf 2013-06-11 16:49:27 +0000
@@ -27,9 +27,10 @@
27# currently only works for bzr, since svn tags are just different URLS)27# currently only works for bzr, since svn tags are just different URLS)
2828
29archive bzr lp:zorba/archive-module zorba-2.929archive bzr lp:zorba/archive-module zorba-2.9
30csv bzr lp:zorba/csv-module zorba-2.930#csv bzr lp:zorba/csv-module
31data-cleaning bzr lp:zorba/data-cleaning-module zorba-2.931csv bzr lp:~zorba-coders/zorba/bug-1180220-util-jvm
32data-formatting bzr lp:zorba/data-formatting-module zorba-2.9.132data-cleaning bzr lp:zorba/data-cleaning-module
33data-formatting bzr lp:zorba/data-formatting-module
33excel bzr lp:zorba/excel-module zorba-2.934excel bzr lp:zorba/excel-module zorba-2.9
34info-extraction bzr lp:zorba/info-extraction-module zorba-2.935info-extraction bzr lp:zorba/info-extraction-module zorba-2.9
35geo bzr lp:zorba/geo-module zorba-2.936geo bzr lp:zorba/geo-module zorba-2.9
@@ -38,17 +39,17 @@
38html bzr lp:zorba/html-module zorba-2.939html bzr lp:zorba/html-module zorba-2.9
39http-client bzr lp:zorba/http-client-module zorba-2.940http-client bzr lp:zorba/http-client-module zorba-2.9
40image bzr lp:zorba/image-module zorba-2.941image bzr lp:zorba/image-module zorba-2.9
41jdbc bzr lp:zorba/jdbc-module zorba-2.942jdbc bzr lp:zorba/jdbc-module
42languages bzr lp:zorba/languages-module zorba-2.943languages bzr lp:zorba/languages-module zorba-2.9
43oracle-nosql-db bzr lp:zorba/oracle-nosql-db-module zorba-2.944oracle-nosql-db bzr lp:zorba/oracle-nosql-db-module
44oauth bzr lp:zorba/oauth-module zorba-2.945oauth bzr lp:zorba/oauth-module zorba-2.9
45process bzr lp:zorba/process-module zorba-2.946process bzr lp:zorba/process-module
46read-pdf bzr lp:zorba/read-pdf-module zorba-2.9.147read-pdf bzr lp:zorba/read-pdf-module
47security bzr lp:zorba/security-module zorba-2.948security bzr lp:zorba/security-module zorba-2.9
48system bzr lp:zorba/system-module zorba-2.949system bzr lp:zorba/system-module zorba-2.9
49email bzr lp:zorba/email-module zorba-2.950email bzr lp:zorba/email-module zorba-2.9
50util-jvm bzr lp:zorba/util-jvm-module zorba-2.9.151util-jvm bzr lp:zorba/util-jvm-module
51schema-tools bzr lp:zorba/schema-tools-module zorba-2.9.152schema-tools bzr lp:zorba/schema-tools-module
52stack bzr lp:zorba/stack-module zorba-2.953stack bzr lp:zorba/stack-module zorba-2.9
53queue bzr lp:zorba/queue-module zorba-2.954queue bzr lp:zorba/queue-module zorba-2.9
54couchbase bzr lp:zorba/couchbase-module zorba-2.955couchbase bzr lp:zorba/couchbase-module zorba-2.9
5556
=== 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-11 16:49:27 +0000
@@ -16,25 +16,28 @@
1616
17#include "file.h"17#include "file.h"
1818
19// standard
19#include <fstream>20#include <fstream>
20#include <memory>21#include <memory>
21#include <sstream>22#include <sstream>
22#include <stdexcept>23#include <stdexcept>
2324
25// Zorba
24#include <zorba/base64.h>26#include <zorba/base64.h>
27#include <zorba/diagnostic_list.h>
25#include <zorba/empty_sequence.h>28#include <zorba/empty_sequence.h>
26#include <zorba/diagnostic_list.h>
27#include <zorba/file.h>
28#include <zorba/serializer.h>29#include <zorba/serializer.h>
29#include <zorba/singleton_item_sequence.h>30#include <zorba/singleton_item_sequence.h>
30#include <zorba/util/path.h>31#include <zorba/transcode_stream.h>
31#include <zorba/user_exception.h>32#include <zorba/user_exception.h>
32#include <zorba/transcode_stream.h>33#include <zorba/util/fs_util.h>
34#include <zorba/util/stream_util.h>
3335
36// local
34#include "file_module.h"37#include "file_module.h"
3538
3639namespace zorba {
37namespace zorba { namespace filemodule {40namespace filemodule {
3841
39//*****************************************************************************42//*****************************************************************************
4043
@@ -45,129 +48,87 @@
4548
46ItemSequence_t49ItemSequence_t
47CreateDirectoryFunction::evaluate(50CreateDirectoryFunction::evaluate(
48 const ExternalFunction::Arguments_t& aArgs,51 ExternalFunction::Arguments_t const &aArgs,
49 const StaticContext* aSctxCtx,52 StaticContext const*,
50 const DynamicContext* aDynCtx) const53 DynamicContext const* ) const
51{54{
52 String lFileStr = getFilePathString(aArgs, 0);55 String const path( getFilePathString( aArgs, 0 ) );
53 File_t lFile = File::createFile(lFileStr.c_str());56
5457 if ( fs::get_type( path ) )
55 // precondition58 raiseFileError( "FOFL0002", "file already exists", path );
56 if (lFile->isFile()) {59
57 raiseFileError("FOFL0002", "A file already exists at this path", lFile->getFilePath());
58 }
59
60 // actual mkdir
61 try {60 try {
62 lFile->mkdir(true);61 fs::mkdir( path );
63 } catch (ZorbaException const& ze) {62 }
64 std::stringstream lSs;63 catch ( std::exception const &e ) {
65 lSs << "An unknown error occured: " << ze.what() << "Can not create directory";64 throw raiseFileError( "FOFL9999", e.what(), path );
66 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());65 }
67 } catch (...) {66
68 //assert(false); if this happens errors are not proprly thrown67 return ItemSequence_t( new EmptySequence() );
69 raiseFileError("FOFL9999", "Can not create directory", lFile->getFilePath());
70 }
71
72 // postcondition
73 if (!(lFile->isDirectory())) {
74 raiseFileError("FOFL9999", "Can not create directory", lFile->getFilePath());
75 }
76
77 return ItemSequence_t(new EmptySequence());
78}68}
7969
80//*****************************************************************************70//*****************************************************************************
8171
82DeleteFileImplFunction::DeleteFileImplFunction(const FileModule* aModule)72DeleteFileImplFunction::DeleteFileImplFunction(const FileModule* aModule) :
83 : FileFunction(aModule)73 FileFunction(aModule)
84{74{
85}75}
8676
87ItemSequence_t77ItemSequence_t
88DeleteFileImplFunction::evaluate(78DeleteFileImplFunction::evaluate(
89 const ExternalFunction::Arguments_t& aArgs,79 ExternalFunction::Arguments_t const &aArgs,
90 const StaticContext* aSctxCtx,80 StaticContext const*,
91 const DynamicContext* aDynCtx) const81 DynamicContext const* ) const
92{82{
93 String lFileStr = getFilePathString(aArgs, 0);83 String const path( getFilePathString( aArgs, 0 ) );
94 File_t lFile = File::createFile(lFileStr.c_str());84
9585 if ( !fs::get_type( path, false ) )
96 // precondition86 raiseFileError( "FOFL0001", "file not found", path );
97 if (!lFile->exists( false )) {87
98 raiseFileError("FOFL0001", "A file or directory does not exist at this path", lFile->getFilePath());
99 }
100
101 // actual remove
102 try {88 try {
103 lFile->remove();89 fs::remove( path );
104 } catch (ZorbaException const& ze) {90 }
105 std::stringstream lSs;91 catch ( std::exception const &e ) {
106 lSs << "An unknown error occured: " << ze.what() << "Can not delete file";92 throw raiseFileError( "FOFL9999", e.what(), path );
107 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());93 }
108 } catch (...) {94
109 //assert(false); if this happens errors are not proprly thrown95 return ItemSequence_t( new EmptySequence() );
110 raiseFileError("FOFL9999", "Can not delete directory", lFile->getFilePath());
111 }
112
113 // postcondition
114 if (lFile->exists( false )) {
115 raiseFileError("FOFL9999", "The file at this path could not be deleted", lFile->getFilePath());
116 }
117
118 return ItemSequence_t(new EmptySequence());
119}96}
12097
121//*****************************************************************************98//*****************************************************************************
12299
123ReadBinaryFunction::ReadBinaryFunction(const FileModule* aModule)100ReadBinaryFunction::ReadBinaryFunction( FileModule const *aModule ) :
124 : FileFunction(aModule)101 FileFunction( aModule )
125{102{
126}103}
127104
128ItemSequence_t105ItemSequence_t
129ReadBinaryFunction::evaluate(106ReadBinaryFunction::evaluate(
130 const ExternalFunction::Arguments_t& aArgs,107 ExternalFunction::Arguments_t const &aArgs,
131 const StaticContext* aSctxCtx,108 StaticContext const*,
132 const DynamicContext* aDynCtx) const109 DynamicContext const* ) const
133{110{
134 String lFileStr = getFilePathString(aArgs, 0);111 String const path( getFilePathString( aArgs, 0 ) );
135 File_t lFile = File::createFile(lFileStr.c_str());112
136113 fs::type const fs_type = fs::get_type( path );
137 // preconditions114 if ( !fs_type )
138 if (!lFile->exists()) {115 raiseFileError( "FOFL0001", "file not found", path );
139 raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());116 if ( fs_type != fs::file )
140 }117 raiseFileError( "FOFL0004", "not a plain file", path );
141 if (lFile->isDirectory()) {118
142 raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
143 }
144
145 // actual read
146 Item lItem;
147 try {119 try {
148 std::unique_ptr<std::ifstream> lInStream;120 std::unique_ptr<std::ifstream> pin(
149 lInStream.reset( new std::ifstream() );121 new std::ifstream( path.c_str(), std::ios_base::binary )
150 lFile->openInputStream(*lInStream.get(), true, false);122 );
151123 Item item = theModule->getItemFactory()->createStreamableBase64Binary(
152 lItem = theModule->getItemFactory()->createStreamableBase64Binary(124 *pin, &FileModule::streamReleaser, true
153 *lInStream.release(), &FileModule::streamReleaser, true125 );
154 );126 pin.release();
155127 return ItemSequence_t( new SingletonItemSequence( item ) );
156 } catch (ZorbaException const& ze) {128 }
157 std::stringstream lSs;129 catch ( std::exception const &e ) {
158 lSs << "An unknown error occured: " << ze.what() << "Can not read file";130 throw raiseFileError( "FOFL9999", e.what(), path );
159 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());131 }
160 } catch (...) {
161 //assert(false); if this happens errors are not proprly thrown
162 raiseFileError("FOFL9999", "Can not read file", lFile->getFilePath());
163 }
164
165 if (lItem.isNull()) {
166 Item lQName = theModule->getItemFactory()->createQName("http://www.w3.org/2005/xqt-errors", "err", "XPTY0004");
167 throw USER_EXCEPTION(lQName, "Error while building the base64binary item." );
168 }
169
170 return ItemSequence_t(new SingletonItemSequence(lItem));
171}132}
172133
173//*****************************************************************************134//*****************************************************************************
@@ -179,47 +140,43 @@
179140
180ItemSequence_t141ItemSequence_t
181ReadTextFunction::evaluate(142ReadTextFunction::evaluate(
182 const ExternalFunction::Arguments_t& aArgs,143 ExternalFunction::Arguments_t const &aArgs,
183 const StaticContext* aSctxCtx,144 StaticContext const*,
184 const DynamicContext* aDynCtx) const145 DynamicContext const* ) const
185{146{
186 String lFileStr = getFilePathString(aArgs, 0);147 String const path( getFilePathString( aArgs, 0 ) );
187 File_t lFile = File::createFile(lFileStr.c_str());148 String lEncoding( "UTF-8" );
188 String lEncoding("UTF-8");149
189150 fs::type const fs_type = fs::get_type( path );
190 // preconditions151 if ( !fs_type )
191 if (!lFile->exists()) {152 raiseFileError( "FOFL0001", "file not found", path );
192 raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());153 if ( fs_type != fs::file )
193 }154 raiseFileError( "FOFL0004", "not a plain file", path );
194 if (lFile->isDirectory()) {155
195 raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());156 if ( aArgs.size() == 2 )
196 }157 lEncoding = getEncodingArg( aArgs, 1 );
197
198 if (aArgs.size() == 2) {
199 lEncoding = getEncodingArg(aArgs, 1);
200 }
201 158
202 zorba::Item lResult;159 zorba::Item lResult;
203 std::unique_ptr<std::ifstream> lInStream;160
204 if ( transcode::is_necessary( lEncoding.c_str() ) )161 std::unique_ptr<std::ifstream> pin;
205 {162 if ( transcode::is_necessary( lEncoding.c_str() ) ) {
206 try {163 try {
207 lInStream.reset( new transcode::stream<std::ifstream>(lEncoding.c_str()) );164 pin.reset( new transcode::stream<std::ifstream>( lEncoding.c_str() ) );
208 } catch (std::invalid_argument const&)165 }
209 {166 catch ( std::exception const &e ) {
210 raiseFileError("FOFL0006", "Unsupported encoding", lEncoding.c_str());167 throw raiseFileError("FOFL0006", e.what(), lEncoding.c_str() );
211 }168 }
212 }169 } else
213 else170 pin.reset( new std::ifstream() );
214 {171
215 lInStream.reset( new std::ifstream() );172 pin->open( path.c_str() );
216 }173 skip_utf8_bom( *pin );
217 lFile->openInputStream(*lInStream.get(), false, true);
218 lResult = theModule->getItemFactory()->createStreamableString(174 lResult = theModule->getItemFactory()->createStreamableString(
219 *lInStream.release(), &FileModule::streamReleaser, lFileStr.c_str(), true175 *pin, &FileModule::streamReleaser, path.c_str(), true
220 );176 );
221 return ItemSequence_t(new SingletonItemSequence(lResult));177 pin.release();
222178
179 return ItemSequence_t( new SingletonItemSequence( lResult ) );
223}180}
224181
225//*****************************************************************************182//*****************************************************************************
@@ -231,34 +188,30 @@
231188
232ItemSequence_t189ItemSequence_t
233ReadTextLinesFunction::evaluate(190ReadTextLinesFunction::evaluate(
234 const ExternalFunction::Arguments_t& aArgs,191 ExternalFunction::Arguments_t const &aArgs,
235 const StaticContext* aSctxCtx,192 StaticContext const*,
236 const DynamicContext* aDynCtx) const193 DynamicContext const* ) const
237{194{
238 String lFileStr = getFilePathString(aArgs, 0);195 String const path( getFilePathString( aArgs, 0 ) );
239 File_t lFile = File::createFile(lFileStr.c_str());196 String const lEncoding( getEncodingArg( aArgs, 1 ) );
240 String lEncoding("UTF-8");197
241198 fs::type const fs_type = fs::get_type( path );
242 // preconditions199 if ( !fs_type )
243 if (!lFile->exists()) {200 raiseFileError( "FOFL0001", "file not found", path );
244 raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());201 if ( fs_type != fs::file )
245 }202 raiseFileError( "FOFL0004", "not a plain file", path );
246 if (lFile->isDirectory()) {203
247 raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());204 return ItemSequence_t( new LinesItemSequence( path, lEncoding, this ) );
248 }
249
250 lEncoding = getEncodingArg(aArgs, 1);
251
252 return ItemSequence_t(new LinesItemSequence(lFile, lEncoding, this));
253}205}
254206
255ReadTextLinesFunction::LinesItemSequence::LinesItemSequence(207ReadTextLinesFunction::LinesItemSequence::LinesItemSequence(
256 const File_t& aFile,208 String const &aFile,
257 const String& aEncoding,209 String const &aEncoding,
258 const ReadTextLinesFunction* aFunc)210 ReadTextLinesFunction const *aFunc
259 : theFile(aFile),211) :
260 theEncoding(aEncoding),212 theFile( aFile ),
261 theFunc(aFunc)213 theEncoding( aEncoding ),
214 theFunc( aFunc )
262{215{
263}216}
264217
@@ -266,18 +219,19 @@
266ReadTextLinesFunction::LinesItemSequence::getIterator()219ReadTextLinesFunction::LinesItemSequence::getIterator()
267{220{
268 return new ReadTextLinesFunction::LinesItemSequence::LinesIterator(221 return new ReadTextLinesFunction::LinesItemSequence::LinesIterator(
269 theFile, theEncoding, theFunc222 theFile, theEncoding, theFunc
270 );223 );
271}224}
272225
273ReadTextLinesFunction::LinesItemSequence::LinesIterator::LinesIterator(226ReadTextLinesFunction::LinesItemSequence::LinesIterator::LinesIterator(
274 const File_t& aFile,227 String const &aFile,
275 const String& aEncoding,228 String const &aEncoding,
276 const ReadTextLinesFunction* aFunc)229 ReadTextLinesFunction const *aFunc
277 : theFile(aFile),230) :
278 theEncoding(aEncoding),231 theFile(aFile),
279 theFunc(aFunc),232 theEncoding(aEncoding),
280 theStream(0)233 theFunc(aFunc),
234 theStream(0)
281{235{
282}236}
283237
@@ -289,42 +243,32 @@
289void243void
290ReadTextLinesFunction::LinesItemSequence::LinesIterator::open()244ReadTextLinesFunction::LinesItemSequence::LinesIterator::open()
291{245{
292 if ( transcode::is_necessary( theEncoding.c_str() ) )246 if ( transcode::is_necessary( theEncoding.c_str() ) ) {
293 {247 try {
294 try248 theStream = new transcode::stream<std::ifstream>( theEncoding.c_str() );
295 {249 }
296 theStream = new transcode::stream<std::ifstream>(theEncoding.c_str());250 catch ( std::invalid_argument const &e ) {
297 }251 theFunc->raiseFileError( "FOFL0006", e.what(), theEncoding.c_str() );
298 catch (std::invalid_argument const& e)252 }
299 {253 } else
300 theFunc->raiseFileError("FOFL0006", "Unsupported encoding", theEncoding.c_str());
301 }
302 }
303 else
304 {
305 theStream = new std::ifstream();254 theStream = new std::ifstream();
306 }255
307 theFile->openInputStream(*theStream, false, true);256 theStream->open( theFile.c_str() );
308}257}
309258
310bool259bool
311ReadTextLinesFunction::LinesItemSequence::LinesIterator::next(Item& aRes)260ReadTextLinesFunction::LinesItemSequence::LinesIterator::next(Item& aRes)
312{261{
313 if (!theStream || !theStream->good())262 if ( !theStream || !theStream->good() )
314 return false;263 return false;
315264
316 std::string lStr;265 std::string s;
317 getline(*theStream, lStr);266 getline( *theStream, s );
267 if ( theStream->bad() )
268 return false;
318 269
319 if (theStream->bad())270 aRes = theFunc->theModule->getItemFactory()->createString( s );
320 {271 return true;
321 return false;
322 }
323 else
324 {
325 aRes = theFunc->theModule->getItemFactory()->createString(lStr);
326 return true;
327 }
328}272}
329273
330void274void
@@ -342,220 +286,176 @@
342286
343//*****************************************************************************287//*****************************************************************************
344288
345ExistsFunction::ExistsFunction(const FileModule* aModule)289ExistsFunction::ExistsFunction(const FileModule* aModule) :
346 : FileFunction(aModule)290 FileFunction( aModule )
347{291{
348}292}
349293
350ItemSequence_t294ItemSequence_t
351ExistsFunction::evaluate(295ExistsFunction::evaluate(
352 const ExternalFunction::Arguments_t& aArgs,296 ExternalFunction::Arguments_t const &aArgs,
353 const StaticContext* aSctxCtx,297 StaticContext const*,
354 const DynamicContext* aDynCtx) const298 DynamicContext const* ) const
355{299{
356 String const lFileStr = getFilePathString(aArgs, 0);300 String const path = getFilePathString( aArgs, 0 );
357 bool const lFollowSymlinks = getItem(aArgs, 1).getBooleanValue();301 bool const follow_symlink = getItem( aArgs, 1 ).getBooleanValue();
358302 bool const exists = !!fs::get_type( path, follow_symlink );
359 File_t lFile = File::createFile(lFileStr.c_str());303 return ItemSequence_t(
360 bool const lFileExists = lFile->exists(lFollowSymlinks);304 new SingletonItemSequence(
361305 theModule->getItemFactory()->createBoolean( exists )
362 return ItemSequence_t(new SingletonItemSequence(306 )
363 theModule->getItemFactory()->createBoolean(lFileExists)));307 );
364}308}
365309
366//*****************************************************************************310//*****************************************************************************
367311
368IsDirectoryFunction::IsDirectoryFunction(const FileModule* aModule)312IsDirectoryFunction::IsDirectoryFunction( FileModule const *aModule ) :
369 : FileFunction(aModule)313 FileFunction( aModule )
370{314{
371}315}
372316
373ItemSequence_t317ItemSequence_t
374IsDirectoryFunction::evaluate(318IsDirectoryFunction::evaluate(
375 const ExternalFunction::Arguments_t& aArgs,319 ExternalFunction::Arguments_t const &aArgs,
376 const StaticContext* aSctxCtx,320 StaticContext const*,
377 const DynamicContext* aDynCtx) const321 DynamicContext const* ) const
378{322{
379 bool lResult = false;323 String const path( getFilePathString( aArgs, 0 ) );
380 String lFileStr = getFilePathString(aArgs, 0);324 bool const is_directory = fs::get_type( path ) == fs::directory;
381325 return ItemSequence_t(
382 File_t lFile = File::createFile(lFileStr.c_str());326 new SingletonItemSequence(
383 if (lFile->isDirectory()) {327 theModule->getItemFactory()->createBoolean( is_directory )
384 lResult = true;328 )
385 }329 );
386 return ItemSequence_t(new SingletonItemSequence(
387 theModule->getItemFactory()->createBoolean(lResult)));
388}330}
389331
390//*****************************************************************************332//*****************************************************************************
391333
392IsFileFunction::IsFileFunction(const FileModule* aModule)334IsFileFunction::IsFileFunction( FileModule const *aModule ) :
393 : FileFunction(aModule)335 FileFunction( aModule )
394{336{
395}337}
396338
397ItemSequence_t339ItemSequence_t
398IsFileFunction::evaluate(340IsFileFunction::evaluate(
399 const ExternalFunction::Arguments_t& aArgs,341 ExternalFunction::Arguments_t const &aArgs,
400 const StaticContext* aSctxCtx,342 StaticContext const*,
401 const DynamicContext* aDynCtx) const343 DynamicContext const* ) const
402{344{
403 bool lResult = false;345 String const path( getFilePathString( aArgs, 0 ) );
404 String lFileStr = getFilePathString(aArgs, 0);346 bool const is_file = fs::get_type( path ) == fs::file;
405347 return ItemSequence_t(
406 File_t lFile = File::createFile(lFileStr.c_str());348 new SingletonItemSequence(
407 if (lFile->isFile()) {349 theModule->getItemFactory()->createBoolean( is_file )
408 lResult = true;350 )
409 }351 );
410 return ItemSequence_t(new SingletonItemSequence(
411 theModule->getItemFactory()->createBoolean(lResult)));
412}352}
413353
414//*****************************************************************************354//*****************************************************************************
415355
416IsSymlinkFunction::IsSymlinkFunction(const FileModule* aModule)356IsSymlinkFunction::IsSymlinkFunction( FileModule const *aModule ) :
417 : FileFunction(aModule)357 FileFunction( aModule )
418{358{
419}359}
420360
421ItemSequence_t361ItemSequence_t
422IsSymlinkFunction::evaluate(362IsSymlinkFunction::evaluate(
423 const ExternalFunction::Arguments_t& aArgs,363 ExternalFunction::Arguments_t const &aArgs,
424 const StaticContext* aSctxCtx,364 StaticContext const*,
425 const DynamicContext* aDynCtx) const365 DynamicContext const* ) const
426{366{
427 bool lResult = false;367 String const path( getFilePathString( aArgs, 0 ) );
428 String lFileStr = getFilePathString(aArgs, 0);368 bool const is_symlink = fs::get_type( path, false ) == fs::link;
429369 return ItemSequence_t(
430 File_t lFile = File::createFile(lFileStr.c_str());370 new SingletonItemSequence(
431 if (lFile->isLink()) {371 theModule->getItemFactory()->createBoolean( is_symlink )
432 lResult = true;372 )
433 }373 );
434 return ItemSequence_t(new SingletonItemSequence(
435 theModule->getItemFactory()->createBoolean(lResult)));
436}374}
437375
438//*****************************************************************************376//*****************************************************************************
439377
440CopyFileImplFunction::CopyFileImplFunction(const FileModule* aModule)378CopyFileImplFunction::CopyFileImplFunction( FileModule const *aModule ) :
441 : FileFunction(aModule)379 FileFunction( aModule )
442{380{
443}381}
444382
445ItemSequence_t383ItemSequence_t
446CopyFileImplFunction::evaluate(384CopyFileImplFunction::evaluate(
447 const ExternalFunction::Arguments_t& aArgs,385 ExternalFunction::Arguments_t const &aArgs,
448 const StaticContext* aSctxCtx,386 StaticContext const*,
449 const DynamicContext* aDynCtx) const387 DynamicContext const* ) const
450{388{
451 String lSrcFileStr = getFilePathString(aArgs, 0);389 String const src_path( getFilePathString( aArgs, 0 ) );
452 File_t lSrcFile = File::createFile(lSrcFileStr.c_str());390 String dst_path( getFilePathString( aArgs, 1 ) );
453 String lDstStr = getFilePathString(aArgs, 1);391
454 File_t lDst = File::createFile(lDstStr.c_str());392 fs::type const src_type = fs::get_type( src_path );
455393 if ( !src_type )
456 // preconditions394 raiseFileError( "FOFL0001", "file not found", src_path );
457 if (!lSrcFile->exists()) {395 if ( src_type != fs::file )
458 raiseFileError("FOFL0001", "A file does not exist at this path", lSrcFile->getFilePath());396 raiseFileError( "FOFL0004", "not a plain file", src_path );
459 }397
460 // is this a file? (the recursive version is implemented in XQuery)398 fs::type dst_type = fs::get_type( dst_path );
461 if (lSrcFile->isDirectory()) {399 if ( dst_type == fs::directory ) { // we are copying into a directory
462 raiseFileError("FOFL0004", "This operation is non-recursive. The source path points to a directory", lSrcFile->getFilePath());400 fs::append( dst_path, fs::base_name( src_path ) );
463 }401 dst_type = fs::get_type( dst_path );
464402 if ( dst_type == fs::directory )
465 // do we copy into a directory?403 raiseFileError( "FOFL0002", "path already exists", dst_path );
466 if (lDst->isDirectory()) {404 }
467 lDstStr = lDst->getFilePath();405
468 String lSrcPath = lSrcFile->getFilePath();406 if ( src_path == dst_path )
469 int lLastSep = lSrcPath.rfind(File::getDirectorySeparator());407 raiseFileError( "FOFL9999", "source and destination paths must not be equal", src_path );
470 String lName = lSrcPath.substr(lLastSep);408
471 lDstStr = lDstStr.append(lName.c_str());
472 lDst = File::createFile(lDstStr.c_str());
473 }
474
475 // is the destination still is a directory?
476 if (lDst->isDirectory()) {
477 raiseFileError("FOFL0002", "The destination path already exists", lSrcFile->getFilePath());
478 }
479
480 // do we copy a file to its own location?
481 if (lSrcFile->getFilePath() == lDst->getFilePath()) {
482 raiseFileError("FOFL9999", "The source and destination paths can not point to the same file", lSrcFile->getFilePath());
483 }
484
485 // actual copy
486 try {409 try {
487410 std::ifstream fin( src_path.c_str(), std::ios_base::binary );
488 // open the output stream in the desired write mode411 std::ofstream fout( dst_path.c_str(), std::ios_base::binary | std::ios_base::trunc );
489 std::ifstream lInStream;412 char buf[ 8192 ];
490 std::ofstream lOutStream;413 while ( !fin.eof() ) {
491 lSrcFile->openInputStream(lInStream, true, false);414 fin.read( buf, sizeof buf );
492 lDst->openOutputStream(lOutStream, true, false);415 fout.write( buf, fin.gcount() );
493
494 // copy the data
495 char lBuf[1024];
496 while (!lInStream.eof()) {
497 lInStream.read(lBuf, 1024);
498 lOutStream.write(lBuf, lInStream.gcount());
499 } 416 }
500417 }
501 // close the streams418 catch ( std::exception const &e ) {
502 lInStream.close();419 throw raiseFileError( "FOFL9999", e.what(), src_path );
503 lOutStream.close();420 }
504421
505 } catch (ZorbaException const& ze) {422 return ItemSequence_t( new EmptySequence() );
506 std::stringstream lSs;
507 lSs << "An unknown error occured: " << ze.what() << "Can not copy file";
508 raiseFileError("FOFL9999", lSs.str(), lSrcFile->getFilePath());
509 } catch (...) {
510 //assert(false); if this happens errors are not proprly thrown
511 raiseFileError("FOFL9999", "Can not copy file", lSrcFile->getFilePath());
512 }
513
514 return ItemSequence_t(new EmptySequence());
515}423}
516424
517//*****************************************************************************425//*****************************************************************************
518426
519ListFunction::ListFunction(const FileModule* aModule)427ListFunction::ListFunction( FileModule const *aModule ) :
520 : FileFunction(aModule)428 FileFunction( aModule )
521{429{
522}430}
523431
524ItemSequence_t432ItemSequence_t
525ListFunction::evaluate(433ListFunction::evaluate(
526 const ExternalFunction::Arguments_t& aArgs,434 ExternalFunction::Arguments_t const &aArgs,
527 const StaticContext* aSctxCtx,435 StaticContext const*,
528 const DynamicContext* aDynCtx) const436 DynamicContext const* ) const
529{437{
530 String lFileStr = getFilePathString(aArgs, 0);438 String const path( getFilePathString( aArgs, 0 ) );
531 File_t lFile = File::createFile(lFileStr.c_str());439
532440 if ( fs::get_type( path ) != fs::directory )
533 // precondition441 raiseFileError( "FOFL0003", "path is not a directory", path );
534 if (!lFile->isDirectory()) {442
535 raiseFileError("FOFL0003", "The specified path does not point to a directory", lFile->getFilePath());
536 }
537
538 // actual list
539 try {443 try {
540 DirectoryIterator_t lIter = lFile->files();444 return ItemSequence_t(
541 return ItemSequence_t(new IteratorBackedItemSequence(lIter, theModule->getItemFactory()));445 new IteratorBackedItemSequence( path, theModule->getItemFactory() )
542 } catch (ZorbaException const& ze) {446 );
543 std::stringstream lSs;447 }
544 lSs << "An unknown error occured: " << ze.what() << "Can not list directory";448 catch ( std::exception const &e ) {
545 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());449 throw raiseFileError( "FOFL9999", e.what(), path );
546 } catch (...) {450 }
547 //assert(false); if this happens errors are not proprly thrown
548 raiseFileError("FOFL9999", "Can not list directory", lFile->getFilePath());
549 }
550
551 // dummy, this will never be called
552 return ItemSequence_t(new EmptySequence());
553}451}
554452
555ListFunction::IteratorBackedItemSequence::IteratorBackedItemSequence(453ListFunction::IteratorBackedItemSequence::IteratorBackedItemSequence(
556 DirectoryIterator_t& aIter,454 String const& path,
557 ItemFactory* aFactory)455 ItemFactory* aFactory
558 : theIterator(aIter), theItemFactory(aFactory)456) :
457 theIterator( path ),
458 theItemFactory( aFactory )
559{459{
560 is_open = false;460 is_open = false;
561 open_count = 0;461 open_count = 0;
@@ -573,7 +473,7 @@
573void ListFunction::IteratorBackedItemSequence::open()473void ListFunction::IteratorBackedItemSequence::open()
574{474{
575 if (open_count) {475 if (open_count) {
576 theIterator->reset();476 theIterator.reset();
577 }477 }
578 open_count++;478 open_count++;
579 is_open = true;479 is_open = true;
@@ -592,64 +492,57 @@
592bool492bool
593ListFunction::IteratorBackedItemSequence::next(Item& lItem)493ListFunction::IteratorBackedItemSequence::next(Item& lItem)
594{494{
595 std::string lPath;495 if ( !theIterator.next() )
596 if (!theIterator->next(lPath)) {
597 return false;496 return false;
598 }
599497
600 String lUriStr(lPath.c_str());498 String lUriStr( theIterator->name );
601 lItem = theItemFactory->createString(lUriStr);499 lItem = theItemFactory->createString( lUriStr );
602 return true;500 return true;
603}501}
604502
605//*****************************************************************************503//*****************************************************************************
606504
607LastModifiedFunction::LastModifiedFunction(const FileModule* aModule)505LastModifiedFunction::LastModifiedFunction(const FileModule* aModule) :
608 : FileFunction(aModule)506 FileFunction(aModule)
609{507{
610}508}
611509
612ItemSequence_t510ItemSequence_t
613LastModifiedFunction::evaluate(511LastModifiedFunction::evaluate(
614 const ExternalFunction::Arguments_t& aArgs,512 ExternalFunction::Arguments_t const &aArgs,
615 const StaticContext* aSctxCtx,513 StaticContext const*,
616 const DynamicContext* aDynCtx) const514 DynamicContext const* ) const
617{515{
618 String lFileStr = getFilePathString(aArgs, 0);516 String const path( getFilePathString( aArgs, 0 ) );
619 File_t lFile = File::createFile(lFileStr.c_str());517
620518 fs::info info;
621 // precondition519 if ( !fs::get_type( path, &info ) )
622 if (!lFile->exists()) {520 raiseFileError( "FOFL0001", "file not found", path );
623 raiseFileError("FOFL0001", "A file or directory does not exist at this path", lFile->getFilePath());521
624 }
625
626 // actual last modified
627 try {522 try {
628 time_t lTime = lFile->lastModified();523 time_t lTime = info.mtime;
629 // result of localtime needs to be copied.524 // result of localtime needs to be copied.
630 // Otherwise, nasty side effecs do happen525 // Otherwise, nasty side effecs do happen
631 struct tm lT(*localtime(&lTime));526 struct tm lT(*localtime(&lTime));
632 int gmtOffset = LastModifiedFunction::getGmtOffset();527 int gmtOffset = LastModifiedFunction::getGmtOffset();
633528
634 return ItemSequence_t(new SingletonItemSequence(529 return ItemSequence_t(
635 theModule->getItemFactory()->createDateTime(1900 + lT.tm_year,530 new SingletonItemSequence(
636 lT.tm_mon,531 theModule->getItemFactory()->createDateTime(
637 lT.tm_mday,532 1900 + lT.tm_year,
638 lT.tm_hour,533 lT.tm_mon,
639 lT.tm_min, 534 lT.tm_mday,
640 lT.tm_sec,535 lT.tm_hour,
641 gmtOffset)));536 lT.tm_min,
642 } catch (ZorbaException const& ze) {537 lT.tm_sec,
643 std::stringstream lSs;538 gmtOffset
644 lSs << "An unknown error occured: " << ze.what() << "Can not retrieve the last modification timestamp of";539 )
645 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());540 )
646 } catch (...) {541 );
647 //assert(false); if this happens errors are not proprly thrown542 }
648 raiseFileError("FOFL9999", "Can not retrieve the last modification timestamp of", lFile->getFilePath());543 catch ( std::exception const &e ) {
649 }544 throw raiseFileError( "FOFL9999", e.what(), path );
650545 }
651 // dummy, this will never be called
652 return ItemSequence_t(new EmptySequence());
653}546}
654547
655int548int
@@ -675,36 +568,20 @@
675568
676ItemSequence_t569ItemSequence_t
677SizeFunction::evaluate(570SizeFunction::evaluate(
678 const ExternalFunction::Arguments_t& aArgs,571 ExternalFunction::Arguments_t const &aArgs,
679 const StaticContext* aSctxCtx,572 StaticContext const*,
680 const DynamicContext* aDynCtx) const573 DynamicContext const* ) const
681{574{
682 String lFileStr = getFilePathString(aArgs, 0);575 String const path( getFilePathString( aArgs, 0 ) );
683 File_t lFile = File::createFile(lFileStr.c_str());576
684577 fs::info info;
685 // preconditions578 if ( !fs::get_type( path, &info ) )
686 if (!lFile->exists()) {579 raiseFileError( "FOFL0001", "file not found", path );
687 raiseFileError("FOFL0001", "A file does not exist at this path", lFile->getFilePath());580 if ( info.type != fs::file )
688 }581 raiseFileError( "FOFL0004", "not plain file", path );
689 if (lFile->isDirectory()) {
690 raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
691 }
692
693 // actual size
694 File::FileSize_t lFs = -1;
695 try {
696 lFs = lFile->getSize();
697 } catch (ZorbaException const& ze) {
698 std::stringstream lSs;
699 lSs << "An unknown error occured: " << ze.what() << "Can not retrieve the file size of";
700 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
701 } catch (...) {
702 //assert(false); if this happens errors are not proprly thrown
703 raiseFileError("FOFL9999", "Can not retrieve the file size of", lFile->getFilePath());
704 }
705582
706 return ItemSequence_t(new SingletonItemSequence(583 return ItemSequence_t(new SingletonItemSequence(
707 theModule->getItemFactory()->createInteger(lFs)));584 theModule->getItemFactory()->createInteger(info.size)));
708}585}
709586
710//*****************************************************************************587//*****************************************************************************
@@ -716,11 +593,16 @@
716593
717ItemSequence_t594ItemSequence_t
718PathSeparator::evaluate(595PathSeparator::evaluate(
719 const ExternalFunction::Arguments_t& aArgs,596 ExternalFunction::Arguments_t const &aArgs,
720 const StaticContext* aSctxCtx,597 StaticContext const*,
721 const DynamicContext* aDynCtx) const598 DynamicContext const* ) const
722{599{
723 return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(FileFunction::pathSeparator())));600 String const path_separator( 1, fs::path_separator );
601 return ItemSequence_t(
602 new SingletonItemSequence(
603 theModule->getItemFactory()->createString( path_separator )
604 )
605 );
724}606}
725607
726//*****************************************************************************608//*****************************************************************************
@@ -732,11 +614,16 @@
732614
733ItemSequence_t615ItemSequence_t
734DirectorySeparator::evaluate(616DirectorySeparator::evaluate(
735 const ExternalFunction::Arguments_t& aArgs,617 ExternalFunction::Arguments_t const &aArgs,
736 const StaticContext* aSctxCtx,618 StaticContext const*,
737 const DynamicContext* aDynCtx) const619 DynamicContext const* ) const
738{620{
739 return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(FileFunction::directorySeparator())));621 String const dir_separator( 1, fs::dir_separator );
622 return ItemSequence_t(
623 new SingletonItemSequence(
624 theModule->getItemFactory()->createString( dir_separator )
625 )
626 );
740}627}
741628
742//*****************************************************************************629//*****************************************************************************
@@ -748,11 +635,11 @@
748635
749ItemSequence_t636ItemSequence_t
750ResolvePathFunction::evaluate(637ResolvePathFunction::evaluate(
751 const ExternalFunction::Arguments_t& aArgs,638 ExternalFunction::Arguments_t const &aArgs,
752 const StaticContext* aSctxCtx,639 StaticContext const*,
753 const DynamicContext* aDynCtx) const640 DynamicContext const* ) const
754{641{
755 String lPathStr = getFilePathString(aArgs, 0);642 String lPathStr = getFilePathString( aArgs, 0 );
756 String lResult = pathToOSPath(lPathStr);643 String lResult = pathToOSPath(lPathStr);
757644
758 return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(lResult)));645 return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(lResult)));
@@ -766,17 +653,28 @@
766}653}
767654
768ItemSequence_t655ItemSequence_t
769PathToNativeFunction::evaluate(const ExternalFunction::Arguments_t& args,656PathToNativeFunction::evaluate(
770 const StaticContext* aSctxCtx,657 ExternalFunction::Arguments_t const &args,
771 const DynamicContext* aDynCtx) const658 StaticContext const*,
659 DynamicContext const* ) const
772{660{
773 Item pathItem;661 Item pathItem;
774 Iterator_t arg0_iter = args[0]->getIterator();662 Iterator_t arg0_iter = args[0]->getIterator();
775 arg0_iter->open();663 arg0_iter->open();
776 arg0_iter->next(pathItem);664 arg0_iter->next(pathItem);
777 arg0_iter->close();665 arg0_iter->close();
778 String osPath = filesystem_path::normalize_path(pathItem.getStringValue().c_str());666 String const path( pathItem.getStringValue() );
779 return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createString(osPath)));667 try {
668 String const osPath( fs::normalize_path( path ) );
669 return ItemSequence_t(
670 new SingletonItemSequence(
671 theModule->getItemFactory()->createString( osPath )
672 )
673 );
674 }
675 catch ( std::invalid_argument const &e ) {
676 throw raiseFileError( "FOFL9999", e.what(), path );
677 }
780}678}
781679
782//*****************************************************************************680//*****************************************************************************
@@ -788,11 +686,11 @@
788686
789ItemSequence_t687ItemSequence_t
790PathToUriFunction::evaluate(688PathToUriFunction::evaluate(
791 const ExternalFunction::Arguments_t& aArgs,689 ExternalFunction::Arguments_t const &aArgs,
792 const StaticContext* aSctxCtx,690 StaticContext const*,
793 const DynamicContext* aDynCtx) const691 DynamicContext const* ) const
794{692{
795 String lPathStr = getFilePathString(aArgs, 0);693 String lPathStr = getFilePathString( aArgs, 0 );
796 String lResult = pathToUriString(lPathStr);694 String lResult = pathToUriString(lPathStr);
797695
798 return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createAnyURI(lResult)));696 return ItemSequence_t(new SingletonItemSequence(theModule->getItemFactory()->createAnyURI(lResult)));
@@ -869,7 +767,8 @@
869//*****************************************************************************767//*****************************************************************************
870768
871769
872} /* namespace filemodule */ } /* namespace zorba */770} // namespace filemodule
771} // namespace zorba
873772
874#ifdef WIN32773#ifdef WIN32
875# define DLL_EXPORT __declspec(dllexport)774# define DLL_EXPORT __declspec(dllexport)
876775
=== 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-11 16:49:27 +0000
@@ -16,6 +16,8 @@
16#ifndef ZORBA_FILEMODULE_FILE_H16#ifndef ZORBA_FILEMODULE_FILE_H
17#define ZORBA_FILEMODULE_FILE_H17#define ZORBA_FILEMODULE_FILE_H
1818
19#include <zorba/util/fs_util.h>
20
19#include "file_function.h"21#include "file_function.h"
2022
21namespace zorba { 23namespace zorba {
@@ -107,7 +109,7 @@
107109
108 public:110 public:
109 IteratorBackedItemSequence(111 IteratorBackedItemSequence(
110 DirectoryIterator_t& aIter,112 String const& path,
111 zorba::ItemFactory* aFactory);113 zorba::ItemFactory* aFactory);
112114
113 virtual ~IteratorBackedItemSequence();115 virtual ~IteratorBackedItemSequence();
@@ -123,7 +125,7 @@
123 private:125 private:
124 bool is_open;126 bool is_open;
125 int open_count;127 int open_count;
126 DirectoryIterator_t theIterator;128 fs::iterator theIterator;
127 ItemFactory* theItemFactory;129 ItemFactory* theItemFactory;
128 };130 };
129 };131 };
@@ -349,14 +351,14 @@
349 class LinesItemSequence : public ItemSequence351 class LinesItemSequence : public ItemSequence
350 {352 {
351 protected:353 protected:
352 File_t theFile;354 String theFile;
353 String theEncoding;355 String theEncoding;
354 const ReadTextLinesFunction* theFunc;356 const ReadTextLinesFunction* theFunc;
355357
356 class LinesIterator : public Iterator358 class LinesIterator : public Iterator
357 {359 {
358 protected:360 protected:
359 const File_t& theFile;361 const String& theFile;
360 const String& theEncoding;362 const String& theEncoding;
361 const ReadTextLinesFunction* theFunc;363 const ReadTextLinesFunction* theFunc;
362364
@@ -364,7 +366,7 @@
364366
365 public:367 public:
366 LinesIterator(368 LinesIterator(
367 const File_t&,369 const String&,
368 const String&,370 const String&,
369 const ReadTextLinesFunction*);371 const ReadTextLinesFunction*);
370372
@@ -385,7 +387,7 @@
385387
386 public:388 public:
387 LinesItemSequence(389 LinesItemSequence(
388 const File_t& aFile,390 const String& aFile,
389 const String& aEncoding,391 const String& aEncoding,
390 const ReadTextLinesFunction*);392 const ReadTextLinesFunction*);
391393
392394
=== 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-11 16:49:27 +0000
@@ -20,11 +20,10 @@
2020
21#include <zorba/empty_sequence.h>21#include <zorba/empty_sequence.h>
22#include <zorba/diagnostic_list.h>22#include <zorba/diagnostic_list.h>
23#include <zorba/file.h>
24#include <zorba/serializer.h>23#include <zorba/serializer.h>
25#include <zorba/store_consts.h>24#include <zorba/store_consts.h>
26#include <zorba/user_exception.h>25#include <zorba/user_exception.h>
27#include <zorba/util/path.h>26#include <zorba/util/fs_util.h>
28#include <zorba/xquery_functions.h>27#include <zorba/xquery_functions.h>
29#include <zorba/singleton_item_sequence.h>28#include <zorba/singleton_item_sequence.h>
30#include <zorba/zorba.h>29#include <zorba/zorba.h>
@@ -42,23 +41,6 @@
42#include <unistd.h>41#include <unistd.h>
43#endif42#endif
4443
45static zorba::String getCurrentPath()
46{
47#ifdef WIN32
48 wchar_t* wbuffer = _wgetcwd(NULL, 0);
49 char *buffer = (char*)malloc(1024);
50 WideCharToMultiByte(CP_UTF8, 0, wbuffer, -1, buffer, 1024, NULL, NULL);
51#else
52 char buffer[2048];
53 getcwd(buffer, 2048);
54#endif
55 zorba::String result(buffer);
56#ifdef WIN32
57 free(buffer);
58#endif
59 return result;
60}
61
62namespace zorba { namespace filemodule {44namespace zorba { namespace filemodule {
6345
64FileFunction::FileFunction(const FileModule* aModule)46FileFunction::FileFunction(const FileModule* aModule)
@@ -70,16 +52,18 @@
70{52{
71}53}
7254
73void55int
74FileFunction::raiseFileError(56FileFunction::raiseFileError(
75 const std::string& aQName,57 char const *aQName,
76 const std::string& aMessage,58 char const *aMessage,
77 const std::string& aPath) const59 String const &aPath ) const
78{60{
79 std::stringstream lErrorMessage;61 Item const lQName(
80 lErrorMessage << aMessage << ": " << aPath;62 theModule->getItemFactory()->createQName( getURI(), "file", aQName )
81 Item lQName = theModule->getItemFactory()->createQName(getURI(), "file", aQName);63 );
82 throw USER_EXCEPTION(lQName, lErrorMessage.str());64 std::ostringstream lErrorMessage;
65 lErrorMessage << '"' << aPath << "\": " << aMessage;
66 throw USER_EXCEPTION( lQName, lErrorMessage.str() );
83}67}
8468
85String69String
@@ -103,26 +87,22 @@
103 }87 }
104 args_iter->close();88 args_iter->close();
10589
106 return (filesystem_path::normalize_path90 try {
107 (lFileArg.c_str(), getCurrentPath().c_str()));91 return fs::normalize_path(lFileArg, fs::curdir());
108}92 }
10993 catch ( std::invalid_argument const &e ) {
110String94 throw raiseFileError( "FOFL9999", e.what(), lFileArg );
111FileFunction::directorySeparator() {95 }
112 return File::getDirectorySeparator();
113}
114
115String
116FileFunction::pathSeparator() {
117 return File::getPathSeparator();
118}96}
11997
120String98String
121FileFunction::pathToFullOSPath(const String& aPath) const {99FileFunction::pathToFullOSPath(const String& aPath) const {
122 File_t lFile = File::createFile(aPath.c_str());100 try {
123 std::string lPath = lFile->getFilePath();101 return fs::normalize_path( aPath );
124102 }
125 return String(lPath);103 catch ( std::invalid_argument const &e ) {
104 throw raiseFileError( "FOFL9999", e.what(), aPath );
105 }
126}106}
127107
128String108String
@@ -147,31 +127,30 @@
147127
148String128String
149FileFunction::pathToOSPath(const String& aPath) const {129FileFunction::pathToOSPath(const String& aPath) const {
150 File_t lFile = File::createFile(aPath.c_str());130 try {
151 std::string lPath = lFile->getFilePath();131 return fs::normalize_path( aPath );
152132 }
153 return String(lPath);133 catch ( std::invalid_argument const &e ) {
134 throw raiseFileError( "FOFL9999", e.what(), aPath );
135 }
154}136}
155137
156String138String
157FileFunction::pathToUriString(const String& aPath) const {139FileFunction::pathToUriString(const String& aPath) const {
158 std::stringstream lErrorMessage;
159140
160 if(fn::starts_with(aPath,"file://")) {141 if ( fn::starts_with( aPath,"file://" ) ) {
142 std::stringstream lErrorMessage;
161 lErrorMessage << "Please provide a path, not a URI";143 lErrorMessage << "Please provide a path, not a URI";
162 Item lQName = theModule->getItemFactory()->createQName(144 Item lQName = theModule->getItemFactory()->createQName(
163 "http://www.w3.org/2005/xqt-errors",145 "http://www.w3.org/2005/xqt-errors",
164 "err",146 "err",
165 "XPTY0004");147 "XPTY0004");
166 throw USER_EXCEPTION(lQName, lErrorMessage.str() );148 throw USER_EXCEPTION( lQName, lErrorMessage.str() );
167 }149 }
168150
169 File_t lFile = File::createFile(aPath.c_str());151 String uri( aPath );
170152
171 std::string lPath = lFile->getFileUri();153 return uri;
172
173
174 return String(lPath);
175}154}
176155
177#ifdef WIN32156#ifdef WIN32
@@ -187,12 +166,9 @@
187 return false;166 return false;
188 }167 }
189168
190 char lDrive = aString[0];169 char const lDrive = aString[0];
191 // the string is already upper case170 // the string is already upper case
192 if (lDrive < 65 || lDrive > 90) {171 return lDrive >= 'A' && lDrive <= 'Z';
193 return false;
194 }
195 return true;
196}172}
197#endif173#endif
198174
@@ -234,33 +210,27 @@
234ItemSequence_t210ItemSequence_t
235WriterFileFunction::evaluate(211WriterFileFunction::evaluate(
236 const ExternalFunction::Arguments_t& aArgs,212 const ExternalFunction::Arguments_t& aArgs,
237 const StaticContext* aSctxCtx,213 const StaticContext*,
238 const DynamicContext* aDynCtx) const214 const DynamicContext* ) const
239{215{
240 String lFileStr = getFilePathString(aArgs, 0);216 String const lFileStr( getFilePathString(aArgs, 0) );
241 File_t lFile = File::createFile(lFileStr.c_str());217
242218 fs::type const fs_type = fs::get_type( lFileStr );
243 // precondition219 if ( fs_type && fs_type != fs::file )
244 if (lFile->isDirectory())220 raiseFileError( "FOFL0004", "not a plain file", lFileStr );
245 {221
246 raiseFileError("FOFL0004",222 bool const lBinary = isBinary();
247 "The given path points to a directory", lFile->getFilePath());223
248 }224 std::ios_base::openmode mode = std::ios_base::out
249225 | (isAppend() ? std::ios_base::app : std::ios_base::trunc);
250 bool lBinary = isBinary();226 if ( lBinary )
251 // open the output stream in the desired write mode227 mode |= std::ios_base::binary;
252 std::ofstream lOutStream;228
253229 std::ofstream lOutStream( lFileStr.c_str(), mode );
254 // actual write230 if ( !lOutStream ) {
255 try231 std::ostringstream oss;
256 {232 oss << '"' << lFileStr << "\": can not open file for writing";
257 lFile->openOutputStream(lOutStream, lBinary, isAppend());233 raiseFileError( "FOFL9999", oss.str().c_str(), lFileStr );
258 }
259 catch (ZorbaException& ze)
260 {
261 std::stringstream lSs;
262 lSs << "Can not open file for writing: " << ze.what();
263 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
264 }234 }
265235
266 // if this is a binary write236 // if this is a binary write
@@ -320,3 +290,4 @@
320290
321} // namespace filemodule291} // namespace filemodule
322} // namespace zorba292} // namespace zorba
293/* vim:set et sw=2 ts=2: */
323294
=== 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-11 16:49:27 +0000
@@ -44,11 +44,11 @@
44 protected:44 protected:
45 const FileModule* theModule;45 const FileModule* theModule;
4646
47 void47 int
48 raiseFileError(48 raiseFileError(
49 const std::string& qName,49 char const *qName,
50 const std::string& message,50 char const *message,
51 const std::string& path) const;51 const String& path) const;
5252
53 /*53 /*
54 * Gets the argument on position pos as a normalised file system path.54 * Gets the argument on position pos as a normalised file system path.
@@ -73,12 +73,6 @@
73 String73 String
74 pathToUriString(const String& path) const;74 pathToUriString(const String& path) const;
7575
76 static String
77 directorySeparator();
78
79 static String
80 pathSeparator();
81
82 public:76 public:
83 FileFunction(const FileModule* module);77 FileFunction(const FileModule* module);
84 ~FileFunction();78 ~FileFunction();
8579
=== modified file 'src/api/CMakeLists.txt'
--- src/api/CMakeLists.txt 2013-04-10 10:13:31 +0000
+++ src/api/CMakeLists.txt 2013-06-11 16:49:27 +0000
@@ -63,11 +63,6 @@
63 module_info_impl.cpp63 module_info_impl.cpp
64 )64 )
6565
66IF (ZORBA_WITH_FILE_ACCESS)
67 LIST(APPEND API_SRCS
68 fileimpl.cpp)
69ENDIF (ZORBA_WITH_FILE_ACCESS)
70
71IF (NOT ZORBA_NO_FULL_TEXT)66IF (NOT ZORBA_NO_FULL_TEXT)
72 LIST(APPEND API_SRCS67 LIST(APPEND API_SRCS
73 stemmer.cpp68 stemmer.cpp
7469
=== 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 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "stdafx.h"
17
18#include "fileimpl.h"
19
20#include <fstream>
21
22#include <zorba/diagnostic_handler.h>
23#include <zorba/util/file.h>
24
25#include <runtime/util/flowctl_exception.h>
26
27#include "diagnostics/xquery_diagnostics.h"
28
29#ifdef WIN32
30#include <util/ascii_util.h>
31#endif
32
33#include "util/uri_util.h"
34#include "zorbaimpl.h"
35
36namespace zorba {
37
38DirectoryIteratorImpl::DirectoryIteratorImpl(std::string const& aPath) :
39 theInternalDirIter( aPath.c_str() )
40{
41}
42
43bool
44DirectoryIteratorImpl::next(std::string& aPathStr) const
45{
46 if (!theInternalDirIter.next()) {
47 return false;
48 }
49
50 // get the current pointed entry
51 aPathStr = theInternalDirIter.entry_name();
52
53 return true;
54}
55
56void DirectoryIteratorImpl::reset()
57{
58 theInternalDirIter.reset();
59}
60
61FileImpl::FileImpl(std::string const& path)
62 : theDiagnosticHandler(new DiagnosticHandler())
63{
64 theInternalFile = new file(path
65#ifdef WIN32
66 , filesystem_path::CONVERT_SLASHES
67#endif
68 );
69}
70
71FileImpl::~FileImpl()
72{
73 delete theInternalFile;
74 delete theDiagnosticHandler;
75}
76
77File_t
78File::createFile(const std::string& path)
79{
80 return new FileImpl(path);
81}
82
83const char*
84File::getDirectorySeparator()
85{
86 return filesystem_path::get_directory_separator();
87}
88
89const char*
90File::getPathSeparator()
91{
92 return filesystem_path::get_path_separator();
93}
94
95const std::string
96FileImpl::getFilePath() const
97{
98 std::string lResult;
99
100 ZORBA_TRY
101 lResult = theInternalFile->get_path();
102 ZORBA_CATCH
103
104 return lResult;
105}
106
107const std::string
108FileImpl::getFileUri() const
109{
110 std::string lPath;
111
112 ZORBA_TRY
113 lPath = theInternalFile->get_path();
114#ifdef WIN32
115 ascii::replace_all( lPath, '\\', '/' );
116#endif
117
118 std::stringstream lEncodedResult;
119 lEncodedResult << "file:///";
120
121 size_t lCurrentPos = 0;
122 size_t lNextSlashPos = lPath.find_first_of("/");
123 while (lNextSlashPos != std::string::npos) {
124 String lEncodedSegment(lPath.substr(lCurrentPos, lNextSlashPos - lCurrentPos));
125 uri::encode( lEncodedSegment );
126 lEncodedResult << lEncodedSegment << "/";
127 lCurrentPos = lNextSlashPos + 1;
128 lNextSlashPos = lPath.find_first_of("/", lNextSlashPos + 1);
129 }
130
131 String lEncodedSegment(lPath.substr(lCurrentPos));
132 uri::encode( lEncodedSegment );
133 lEncodedResult << lEncodedSegment;
134
135 lPath = lEncodedResult.str();
136 ZORBA_CATCH
137
138 return lPath;
139}
140
141bool
142FileImpl::isDirectory( bool follow_symlinks ) const
143{
144 bool lResult = false;
145
146 ZORBA_TRY
147 lResult = theInternalFile->is_directory( follow_symlinks )
148 || theInternalFile->is_volume( follow_symlinks )
149 || theInternalFile->is_root();
150 ZORBA_CATCH
151
152 return lResult;
153}
154
155bool
156FileImpl::isFile( bool follow_symlinks ) const
157{
158 bool lResult = false;
159
160 ZORBA_TRY
161 lResult = theInternalFile->is_file( follow_symlinks ) || theInternalFile->is_link();
162 ZORBA_CATCH
163
164 return lResult;
165}
166
167bool
168FileImpl::isLink() const
169{
170 bool lResult = false;
171
172 ZORBA_TRY
173 lResult = theInternalFile->is_link();
174 ZORBA_CATCH
175
176 return lResult;
177}
178
179bool
180FileImpl::isVolume( bool follow_symlinks ) const
181{
182 bool lResult = false;
183
184 ZORBA_TRY
185 lResult = theInternalFile->is_volume( follow_symlinks );
186 ZORBA_CATCH
187
188 return lResult;
189}
190
191bool
192FileImpl::isInvalid() const
193{
194 bool lResult = false;
195
196 ZORBA_TRY
197 lResult = theInternalFile->is_invalid();
198 ZORBA_CATCH
199
200 return lResult;
201}
202
203bool
204FileImpl::exists( bool follow_symlinks ) const
205{
206 bool lResult = false;
207
208 ZORBA_TRY
209 lResult = theInternalFile->exists( follow_symlinks );
210 ZORBA_CATCH
211
212 return lResult;
213}
214
215void
216FileImpl::remove()
217{
218 ZORBA_TRY
219 if (theInternalFile->is_directory()) {
220 theInternalFile->rmdir(false);
221 } else {
222 theInternalFile->remove(false);
223 }
224 ZORBA_CATCH
225}
226
227bool
228FileImpl::create()
229{
230 bool lResult = false;
231
232 ZORBA_TRY
233 // if the file/dir exist, return false
234 if (theInternalFile->exists()) {
235 return false;
236 }
237
238 theInternalFile->create();
239
240 // if the file does not exist, return false
241 if (!theInternalFile->exists() || !theInternalFile->is_file()) {
242 return false;
243 }
244
245 lResult = true;
246 ZORBA_CATCH
247
248 return lResult;
249}
250
251bool
252FileImpl::rename(std::string const& newpath)
253{
254 bool lResult = false;
255
256 ZORBA_TRY
257 // if the file/dir does not exist, return false
258 if (!theInternalFile->exists()) {
259 return false;
260 }
261 // if the new path is already used, return false
262 file lNewFile(newpath);
263 if (lNewFile.exists()) {
264 return false;
265 }
266
267 theInternalFile->rename(newpath);
268
269 // if the file does not exist, return false
270 if (!lNewFile.exists()) {
271 return false;
272 }
273
274 lResult = true;
275 ZORBA_CATCH
276
277 return lResult;
278}
279
280File::FileSize_t
281FileImpl::getSize() const
282{
283 ZORBA_TRY
284 return theInternalFile->get_size();
285 ZORBA_CATCH
286 assert(false);
287 return -1;
288}
289
290void
291FileImpl::mkdir(bool aRecursive)
292{
293 ZORBA_TRY
294 if (aRecursive) {
295 theInternalFile->deep_mkdir();
296 } else {
297 theInternalFile->mkdir();
298 }
299 ZORBA_CATCH
300}
301
302DirectoryIterator_t
303FileImpl::files() const
304{
305 return new DirectoryIteratorImpl(theInternalFile->get_path());
306}
307
308void
309FileImpl::openInputStream(std::ifstream& aInStream, bool binary, bool trimByteOrderMark) const
310{
311 ZORBA_TRY
312 std::string lPath(theInternalFile->get_path());
313
314 if (!theInternalFile->exists())
315 throw XQUERY_EXCEPTION(
316 err::FODC0002, ERROR_PARAMS( lPath, ZED( FileNotFoundOrReadable ) )
317 );
318 if (!theInternalFile->is_file())
319 throw XQUERY_EXCEPTION(
320 err::FODC0002, ERROR_PARAMS( lPath, ZED( NotPlainFile ) )
321 );
322
323 std::ios_base::openmode lMode = std::ifstream::in;
324 if (binary) {
325 lMode |= std::ios_base::binary;
326 }
327#ifndef WIN32
328 aInStream.open(lPath.c_str(), lMode);
329#else
330 WCHAR wpath_str[1024];
331 wpath_str[0] = 0;
332 if(MultiByteToWideChar(CP_UTF8,
333 0, lPath.c_str(), -1,
334 wpath_str, sizeof(wpath_str)/sizeof(WCHAR)) == 0)
335 {//probably there is some invalid utf8 char, try the Windows ACP
336 MultiByteToWideChar(CP_ACP,
337 0, lPath.c_str(), -1,
338 wpath_str, sizeof(wpath_str)/sizeof(WCHAR));
339 }
340 aInStream.open(wpath_str, lMode);
341#endif
342
343 if (aInStream.is_open() == false)
344 throw XQUERY_EXCEPTION(
345 err::FODC0002, ERROR_PARAMS( lPath, ZED( FileNotFoundOrReadable ) )
346 );
347
348 if (trimByteOrderMark) {
349 char lBuf[3];
350 aInStream.read(lBuf, 3);
351 if (!aInStream.good() || lBuf[0] != (char)0xEF || lBuf[1] != (char)0xBB || lBuf[2] != (char)0xBF ) {
352 aInStream.seekg(0);
353 }
354 }
355 ZORBA_CATCH
356}
357
358void
359FileImpl::openOutputStream(std::ofstream& aOutStream, bool binary, bool append) const
360{
361 ZORBA_TRY
362 std::string lPath(theInternalFile->get_path());
363
364 if (theInternalFile->exists() && !theInternalFile->is_file())
365 throw XQUERY_EXCEPTION(
366 err::FODC0002, ERROR_PARAMS( lPath, ZED( NotPlainFile ) )
367 );
368
369 std::ios_base::openmode lMode = std::ifstream::out;
370 lMode |= append ? std::ios_base::app : std::ios_base::trunc;
371 if (binary) {
372 lMode |= std::ios_base::binary;
373 }
374#ifndef WIN32
375 aOutStream.open(lPath.c_str(), lMode);
376#else
377 WCHAR wpath_str[1024];
378 wpath_str[0] = 0;
379 if(MultiByteToWideChar(CP_UTF8,
380 0, lPath.c_str(), -1,
381 wpath_str, sizeof(wpath_str)/sizeof(WCHAR)) == 0)
382 {//probably there is some invalid utf8 char, try the Windows ACP
383 MultiByteToWideChar(CP_ACP,
384 0, lPath.c_str(), -1,
385 wpath_str, sizeof(wpath_str)/sizeof(WCHAR));
386 }
387 aOutStream.open(wpath_str, lMode);
388#endif
389
390 if (aOutStream.is_open() == false)
391 throw XQUERY_EXCEPTION(
392 err::FODC0002, ERROR_PARAMS( lPath, ZED( FileNotFoundOrReadable ) )
393 );
394 ZORBA_CATCH
395}
396
397time_t
398FileImpl::lastModified() const
399{
400 return theInternalFile->lastModified();
401}
402
403} // namespace zorba
404/* vim:set et sw=2 ts=2: */
4050
=== 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 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17#ifndef XQP_FILE_IMPL_H
18#define XQP_FILE_IMPL_H
19
20#include <iostream>
21#include <zorba/file.h>
22
23#include "util/fs_util.h"
24
25namespace zorba {
26
27 class file;
28 class DiagnosticHandler;
29
30
31class DirectoryIteratorImpl : public DirectoryIterator
32{
33private:
34
35 mutable fs::iterator theInternalDirIter;
36
37public:
38
39 DirectoryIteratorImpl(std::string const& aPath);
40
41 bool next(std::string& aPathStr) const;
42 void reset();
43};
44
45
46class FileImpl : public File
47{
48private:
49
50 zorba::file* theInternalFile;
51
52 DiagnosticHandler* theDiagnosticHandler;
53
54public:
55
56 FileImpl(std::string const& _path);
57
58 ~FileImpl();
59
60
61public: // public methods
62
63 const std::string getFilePath() const;
64 const std::string getFileUri() const;
65
66 bool isDirectory( bool follow_symlinks = true ) const;
67 bool isFile( bool follow_symlinks = true ) const;
68 bool isLink() const;
69 bool isVolume( bool follow_symlinks = true ) const;
70 bool isInvalid() const; // deprecated
71 bool exists( bool follow_symlinks = true ) const;
72
73 void remove();
74 bool create();
75 bool rename(std::string const& newpath);
76
77 FileSize_t getSize() const;
78
79 void mkdir(bool recursive = true);
80
81 DirectoryIterator_t files() const;
82
83 void openInputStream(std::ifstream& aInStream, bool binary, bool trimByteOrderMark) const;
84
85 void openOutputStream(std::ofstream& aOutStream, bool binary, bool append) const;
86
87 time_t lastModified() const;
88};
89
90
91} /* namespace zorba */
92
93#endif
94/* vim:set et sw=2 ts=2: */
950
=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2013-03-25 23:02:19 +0000
+++ src/api/staticcontextimpl.cpp 2013-06-11 16:49:27 +0000
@@ -23,7 +23,7 @@
23#include <zorba/diagnostic_handler.h>23#include <zorba/diagnostic_handler.h>
24#include <zorba/static_context_consts.h>24#include <zorba/static_context_consts.h>
25#include <zorba/typeident.h>25#include <zorba/typeident.h>
26#include <zorba/util/path.h>26#include <zorba/util/fs_util.h>
27#include <zorba/empty_sequence.h>27#include <zorba/empty_sequence.h>
28#include <zorba/singleton_item_sequence.h>28#include <zorba/singleton_item_sequence.h>
2929
@@ -1131,9 +1131,9 @@
1131 {1131 {
1132 aInternalStrings.push_back(Unmarshaller::getInternalString(*lIter).c_str());1132 aInternalStrings.push_back(Unmarshaller::getInternalString(*lIter).c_str());
1133 zstring& lPath = aInternalStrings.back();1133 zstring& lPath = aInternalStrings.back();
1134 if (lPath[lPath.length() - 1] != *filesystem_path::get_directory_separator())1134 if (lPath[lPath.length() - 1] != fs::dir_separator)
1135 {1135 {
1136 lPath.append(filesystem_path::get_directory_separator());1136 lPath += fs::dir_separator;
1137 }1137 }
1138 }1138 }
1139 }1139 }
11401140
=== 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-11 16:49:27 +0000
@@ -19,9 +19,9 @@
1919
20#ifndef ZORBA_NO_FULL_TEXT20#ifndef ZORBA_NO_FULL_TEXT
2121
22#include <zorba/internal/cxx_util.h>
22#include "api/unmarshaller.h"23#include "api/unmarshaller.h"
23#include "diagnostics/assert.h"24#include "diagnostics/assert.h"
24#include "util/cxx_util.h"
2525
26#include "stemmer_wrappers.h"26#include "stemmer_wrappers.h"
2727
2828
=== 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-11 16:49:27 +0000
@@ -19,9 +19,9 @@
1919
20#ifndef ZORBA_NO_FULL_TEXT20#ifndef ZORBA_NO_FULL_TEXT
2121
22#include <zorba/internal/cxx_util.h>
22#include "api/unmarshaller.h"23#include "api/unmarshaller.h"
23#include "diagnostics/assert.h"24#include "diagnostics/assert.h"
24#include "util/cxx_util.h"
2525
26#include "thesaurus_wrappers.h"26#include "thesaurus_wrappers.h"
2727
2828
=== 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-11 16:49:27 +0000
@@ -15,11 +15,11 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include <zorba/internal/cxx_util.h>
18#include <zorba/zorba_string.h>19#include <zorba/zorba_string.h>
1920
20#include "api/unmarshaller.h"21#include "api/unmarshaller.h"
21#include "util/ascii_util.h"22#include "util/ascii_util.h"
22#include "util/cxx_util.h"
23#include "util/regex.h"23#include "util/regex.h"
24#include "util/string_util.h"24#include "util/string_util.h"
25#include "util/uri_util.h"25#include "util/uri_util.h"
2626
=== 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-11 16:49:27 +0000
@@ -16,11 +16,11 @@
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include <zorba/error.h>18#include <zorba/error.h>
19#include <zorba/internal/cxx_util.h>
1920
20#include "diagnostics/xquery_diagnostics.h"21#include "diagnostics/xquery_diagnostics.h"
21#include "types/casting.h"22#include "types/casting.h"
22#include "util/ascii_util.h"23#include "util/ascii_util.h"
23#include "util/cxx_util.h"
24#include "util/indent.h"24#include "util/indent.h"
25#include "util/stl_util.h"25#include "util/stl_util.h"
26#include "zorbautils/locale.h"26#include "zorbautils/locale.h"
2727
=== 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-11 16:49:27 +0000
@@ -18,6 +18,7 @@
18#define ZORBA_COMPILER_FTNODE_H18#define ZORBA_COMPILER_FTNODE_H
1919
20#include <zorba/locale.h>20#include <zorba/locale.h>
21#include <zorba/internal/cxx_util.h>
2122
22#include "common/shared_types.h"23#include "common/shared_types.h"
2324
@@ -29,8 +30,6 @@
2930
30#include "runtime/base/plan_iterator.h"31#include "runtime/base/plan_iterator.h"
3132
32#include "util/cxx_util.h"
33
34#include "zorbatypes/rchandle.h"33#include "zorbatypes/rchandle.h"
35#include "zorbatypes/zstring.h"34#include "zorbatypes/zstring.h"
3635
3736
=== 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-11 16:49:27 +0000
@@ -15,7 +15,7 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "util/cxx_util.h"18#include <zorba/internal/cxx_util.h>
1919
20#include "expr_visitor.h"20#include "expr_visitor.h"
21#include "ftnode.h"21#include "ftnode.h"
2222
=== 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-11 16:49:27 +0000
@@ -15,7 +15,7 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "util/cxx_util.h"18#include <zorba/internal/cxx_util.h>
1919
20#include "ft_types.h"20#include "ft_types.h"
2121
2222
=== 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-11 16:49:27 +0000
@@ -180,7 +180,7 @@
180 // If module-path entry is relative, normalize it against the180 // If module-path entry is relative, normalize it against the
181 // static context's base URI.181 // static context's base URI.
182 if (!fs::is_absolute(*lIter)) {182 if (!fs::is_absolute(*lIter)) {
183 zstring lAbsPath = fs::get_normalized_path(*lIter, aSctx.get_base_uri());183 zstring lAbsPath = fs::normalize_path(*lIter, aSctx.get_base_uri());
184 lCandidateURI.append(lAbsPath);184 lCandidateURI.append(lAbsPath);
185 }185 }
186 else {186 else {
187187
=== 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-11 16:49:27 +0000
@@ -15,9 +15,9 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include <zorba/internal/cxx_util.h>
1819
19#include "context/default_url_resolvers.h"20#include "context/default_url_resolvers.h"
20#include "util/cxx_util.h"
21#include "util/uri_util.h"21#include "util/uri_util.h"
22#include "util/http_util.h"22#include "util/http_util.h"
23#include "util/fs_util.h"23#include "util/fs_util.h"
@@ -125,13 +125,18 @@
125 if (lScheme != uri::file) {125 if (lScheme != uri::file) {
126 return NULL;126 return NULL;
127 }127 }
128 zstring lPath = fs::get_normalized_path(aUrl);128 try {
129 if (fs::get_type(lPath) == fs::file) {129 std::string lPath( fs::normalize_path(aUrl) );
130 std::ifstream* lStream = new std::ifstream(lPath.c_str());130 if (fs::get_type(lPath) == fs::file) {
131 return new StreamResource(131 std::ifstream* lStream = new std::ifstream(lPath.c_str());
132 lStream, &fileStreamReleaser, "", true /* seekable */);132 return new StreamResource(
133 }133 lStream, &fileStreamReleaser, "", true /* seekable */);
134 return NULL;134 }
135 return NULL;
136 }
137 catch ( std::invalid_argument const &e ) {
138 throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
139 }
135}140}
136141
137/******142/******
138143
=== 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-11 16:49:27 +0000
@@ -28,14 +28,15 @@
28#ifdef WIN3228#ifdef WIN32
29# include <strsafe.h>29# include <strsafe.h>
30#endif30#endif
3131#include <fstream>
32#include <diagnostics/xquery_diagnostics.h>32
33#include <zorbatypes/URI.h>33#include "diagnostics/xquery_diagnostics.h"
34#include "zorbatypes/URI.h"
35
34#include <zorba/external_module.h>36#include <zorba/external_module.h>
35#include <zorba/zorba_string.h>37#include <zorba/zorba_string.h>
36#include <context/get_current_lib_suffix.h>38#include <context/get_current_lib_suffix.h>
37#include <fstream>39#include <zorba/util/error_util.h>
38#include <util/error_util.h>
3940
40namespace zorba {41namespace zorba {
4142
4243
=== modified file 'src/diagnostics/assert.h'
--- src/diagnostics/assert.h 2013-02-07 17:24:36 +0000
+++ src/diagnostics/assert.h 2013-06-11 16:49:27 +0000
@@ -22,7 +22,7 @@
2222
23#include <sstream>23#include <sstream>
2424
25#include "util/cxx_util.h"25#include <zorba/internal/cxx_util.h>
2626
27namespace zorba {27namespace zorba {
2828
2929
=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml 2013-06-04 00:34:52 +0000
+++ src/diagnostics/diagnostic_en.xml 2013-06-11 16:49:27 +0000
@@ -4061,10 +4061,6 @@
4061 <value>promotion not possible</value>4061 <value>promotion not possible</value>
4062 </entry>4062 </entry>
40634063
4064 <entry key="QuotedColon_23">
4065 <value>"$2": $3</value>
4066 </entry>
4067
4068 <entry key="SEPM0009_Not10">4064 <entry key="SEPM0009_Not10">
4069 <value>the version parameter has a value other than "1.0" and the doctype-system parameter is specified</value>4065 <value>the version parameter has a value other than "1.0" and the doctype-system parameter is specified</value>
4070 </entry>4066 </entry>
40714067
=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp 2013-06-04 01:32:30 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp 2013-06-11 16:49:27 +0000
@@ -779,7 +779,6 @@
779 { "~ParseFragmentInvalidOptions", "invalid options passed to the parse-xml:parse() function, the element must be in the schema target namespace" },779 { "~ParseFragmentInvalidOptions", "invalid options passed to the parse-xml:parse() function, the element must be in the schema target namespace" },
780 { "~ParseFragmentOptionCombinationNotAllowed", "only one of the <schema-validate/>, <DTD-validate/> or <parse-external-parsed-entity/> options can be specified" },780 { "~ParseFragmentOptionCombinationNotAllowed", "only one of the <schema-validate/>, <DTD-validate/> or <parse-external-parsed-entity/> options can be specified" },
781 { "~PromotionImpossible", "promotion not possible" },781 { "~PromotionImpossible", "promotion not possible" },
782 { "~QuotedColon_23", "\"$2\": $3" },
783#if defined(ZORBA_NO_ICU)782#if defined(ZORBA_NO_ICU)
784 { "~REGEX_BROKEN_PIs_CONSTRUCT", "broken \\\\p{Is} construct; valid characters are [a-zA-Z0-9-]" },783 { "~REGEX_BROKEN_PIs_CONSTRUCT", "broken \\\\p{Is} construct; valid characters are [a-zA-Z0-9-]" },
785#endif784#endif
786785
=== 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-11 16:49:27 +0000
@@ -319,7 +319,6 @@
319#define ZED_XMLParserInitFailed "~XMLParserInitFailed"319#define ZED_XMLParserInitFailed "~XMLParserInitFailed"
320#define ZED_XMLParserNoCreateTree "~XMLParserNoCreateTree"320#define ZED_XMLParserNoCreateTree "~XMLParserNoCreateTree"
321#define ZED_PromotionImpossible "~PromotionImpossible"321#define ZED_PromotionImpossible "~PromotionImpossible"
322#define ZED_QuotedColon_23 "~QuotedColon_23"
323#define ZED_SEPM0009_Not10 "~SEPM0009_Not10"322#define ZED_SEPM0009_Not10 "~SEPM0009_Not10"
324#define ZED_SEPM0009_NotOmit "~SEPM0009_NotOmit"323#define ZED_SEPM0009_NotOmit "~SEPM0009_NotOmit"
325#define ZED_SchemaUnexpected "~SchemaUnexpected"324#define ZED_SchemaUnexpected "~SchemaUnexpected"
326325
=== 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-11 16:49:27 +0000
@@ -18,13 +18,13 @@
18#ifndef ZORBA_USER_EXCEPTION_H18#ifndef ZORBA_USER_EXCEPTION_H
19#define ZORBA_USER_EXCEPTION_H19#define ZORBA_USER_EXCEPTION_H
2020
21#include <zorba/internal/cxx_util.h>
21#include <zorba/item.h>22#include <zorba/item.h>
22#include <zorba/user_exception.h>23#include <zorba/user_exception.h>
2324
24#include "api/unmarshaller.h"25#include "api/unmarshaller.h"
25#include "compiler/parser/query_loc.h"26#include "compiler/parser/query_loc.h"
26#include "store/api/item.h"27#include "store/api/item.h"
27#include "util/cxx_util.h"
28#include "util/stl_util.h"28#include "util/stl_util.h"
2929
30namespace zorba {30namespace zorba {
3131
=== 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-11 16:49:27 +0000
@@ -22,12 +22,11 @@
2222
23#include <zorba/config.h>23#include <zorba/config.h>
24#include <zorba/internal/unique_ptr.h>24#include <zorba/internal/unique_ptr.h>
25#include <zorba/util/error_util.h>
2526
26// TODO: this #include is temporary27// TODO: this #include is temporary
27#include <zorba/diagnostic_list.h>28#include <zorba/diagnostic_list.h>
2829
29#include "util/error_util.h"
30
31#include "diagnostic.h"30#include "diagnostic.h"
32#include "dict.h"31#include "dict.h"
33#include "xquery_exception.h"32#include "xquery_exception.h"
3433
=== 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-11 16:49:27 +0000
@@ -279,7 +279,7 @@
279 case uri::file:279 case uri::file:
280 try {280 try {
281 o << (as_xml ? " uri=\"" : "<") 281 o << (as_xml ? " uri=\"" : "<")
282 << fs::get_normalized_path( uri ) 282 << fs::normalize_path( uri )
283 << (as_xml ? '"' : '>');283 << (as_xml ? '"' : '>');
284 break;284 break;
285 }285 }
286286
=== modified file 'src/precompiled/stdafx.h'
--- src/precompiled/stdafx.h 2013-04-17 18:37:33 +0000
+++ src/precompiled/stdafx.h 2013-06-11 16:49:27 +0000
@@ -31,6 +31,7 @@
31 #include <set>31 #include <set>
32 #include <sys/timeb.h>32 #include <sys/timeb.h>
3333
34 #include <zorba/internal/cxx_util.h>
34 #include "runtime/sequences/sequences.h"35 #include "runtime/sequences/sequences.h"
35 #include "diagnostics/xquery_diagnostics.h"36 #include "diagnostics/xquery_diagnostics.h"
36 #include "xercesc/util/xercesdefs.hpp"37 #include "xercesc/util/xercesdefs.hpp"
@@ -48,7 +49,6 @@
48 #include <zorba/store_manager.h>49 #include <zorba/store_manager.h>
49 #include <zorba/xquery.h>50 #include <zorba/xquery.h>
50 #include <zorba/xquery_exception.h>51 #include <zorba/xquery_exception.h>
51 #include "util/cxx_util.h"
52 #include "diagnostics/assert.h"52 #include "diagnostics/assert.h"
53 #include "zorbatypes/mapm/m_apm_lc.h"53 #include "zorbatypes/mapm/m_apm_lc.h"
54 #include "zorbatypes/datetime/parse.h"54 #include "zorbatypes/datetime/parse.h"
5555
=== modified file 'src/runtime/full_text/apply.cpp'
--- src/runtime/full_text/apply.cpp 2013-06-07 21:22:39 +0000
+++ src/runtime/full_text/apply.cpp 2013-06-11 16:49:27 +0000
@@ -19,17 +19,17 @@
19#include <set>19#include <set>
20#include <vector>20#include <vector>
2121
22#include <zorba/internal/cxx_util.h>
22#include <zorba/tokenizer.h>23#include <zorba/tokenizer.h>
23#include <context/uri_resolver.h>
2424
25#include "compiler/expression/ftnode.h"25#include "compiler/expression/ftnode.h"
26#include "context/uri_resolver.h"
26#include "diagnostics/dict.h"27#include "diagnostics/dict.h"
27#include "diagnostics/xquery_diagnostics.h"28#include "diagnostics/xquery_diagnostics.h"
28#include "store/api/item.h"29#include "store/api/item.h"
29#include "store/api/item_factory.h"30#include "store/api/item_factory.h"
30#include "store/api/store.h"31#include "store/api/store.h"
31#include "system/globalenv.h"32#include "system/globalenv.h"
32#include "util/cxx_util.h"
33#include "util/indent.h"33#include "util/indent.h"
34#include "util/stl_util.h"34#include "util/stl_util.h"
35#include "zorbamisc/ns_consts.h"35#include "zorbamisc/ns_consts.h"
3636
=== 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-11 16:49:27 +0000
@@ -23,12 +23,12 @@
23// needs to be #include'd into the .cpp generated from the ft_module.xml file.23// needs to be #include'd into the .cpp generated from the ft_module.xml file.
24//24//
2525
26#include <deque>
27
28#include <zorba/internal/cxx_util.h>
26#include <zorba/tokenizer.h>29#include <zorba/tokenizer.h>
2730
28#include <deque>
29
30#include "store/api/item.h"31#include "store/api/item.h"
31#include "util/cxx_util.h"
32#include "zorbatypes/ft_token.h"32#include "zorbatypes/ft_token.h"
3333
34#include "ft_module_util.h"34#include "ft_module_util.h"
3535
=== 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-11 16:49:27 +0000
@@ -15,7 +15,8 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "util/cxx_util.h"18#include <zorba/internal/cxx_util.h>
19
19#include "util/stl_util.h"20#include "util/stl_util.h"
20#include "diagnostics/assert.h"21#include "diagnostics/assert.h"
2122
2223
=== 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-11 16:49:27 +0000
@@ -16,11 +16,11 @@
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include <zorba/config.h>18#include <zorba/config.h>
19#include <zorba/internal/cxx_util.h>
1920
20#include "context/static_context.h"21#include "context/static_context.h"
21#include "context/uri_resolver.h"22#include "context/uri_resolver.h"
22#include "util/ascii_util.h"23#include "util/ascii_util.h"
23#include "util/cxx_util.h"
24#include "util/mmap_file.h"24#include "util/mmap_file.h"
25#include "util/stl_util.h"25#include "util/stl_util.h"
26#include "util/uri_util.h"26#include "util/uri_util.h"
2727
=== 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-11 16:49:27 +0000
@@ -17,14 +17,14 @@
1717
18#include <cctype>18#include <cctype>
1919
20#include <zorba/internal/cxx_util.h>
21
20#include "compiler/expression/ftnode.h"22#include "compiler/expression/ftnode.h"
21#include "diagnostics/assert.h"23#include "diagnostics/assert.h"
22#include "store/api/store.h"24#include "store/api/store.h"
23#include "util/cxx_util.h"25#include "system/globalenv.h"
24#include "util/stl_util.h"26#include "util/stl_util.h"
2527
26#include "system/globalenv.h"
27
28#include "ft_stop_words_set.h"28#include "ft_stop_words_set.h"
29#include "ft_token_matcher.h"29#include "ft_token_matcher.h"
30#include "ft_util.h"30#include "ft_util.h"
3131
=== 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-11 16:49:27 +0000
@@ -15,7 +15,8 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "util/cxx_util.h"18#include <zorba/internal/cxx_util.h>
19
19#include "diagnostics/assert.h"20#include "diagnostics/assert.h"
2021
21#include "ft_token_seq_iterator.h"22#include "ft_token_seq_iterator.h"
2223
=== 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-11 16:49:27 +0000
@@ -17,12 +17,12 @@
17#ifndef ZORBA_FULL_TEXT_UTIL_H17#ifndef ZORBA_FULL_TEXT_UTIL_H
18#define ZORBA_FULL_TEXT_UTIL_H18#define ZORBA_FULL_TEXT_UTIL_H
1919
20#include <zorba/internal/cxx_util.h>
20#include <zorba/item.h>21#include <zorba/item.h>
21#include <zorba/locale.h>22#include <zorba/locale.h>
2223
23#include "compiler/expression/ftnode.h"24#include "compiler/expression/ftnode.h"
24#include "store/api/item.h"25#include "store/api/item.h"
25#include "util/cxx_util.h"
26#include "zorbatypes/schema_types.h"26#include "zorbatypes/schema_types.h"
2727
28#include "ft_match.h"28#include "ft_match.h"
2929
=== 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-11 16:49:27 +0000
@@ -19,13 +19,14 @@
19#include <limits>19#include <limits>
20#include <memory>20#include <memory>
2121
22#include <zorba/internal/cxx_util.h>
23
22#include "compiler/expression/ft_expr.h"24#include "compiler/expression/ft_expr.h"
23#include "compiler/expression/ftnode.h"25#include "compiler/expression/ftnode.h"
24#include "compiler/parser/query_loc.h"26#include "compiler/parser/query_loc.h"
25#include "diagnostics/xquery_diagnostics.h"27#include "diagnostics/xquery_diagnostics.h"
26#include "store/api/store.h"28#include "store/api/store.h"
27#include "system/globalenv.h"29#include "system/globalenv.h"
28#include "util/cxx_util.h"
29#include "util/indent.h"30#include "util/indent.h"
30#include "util/stl_util.h"31#include "util/stl_util.h"
31#include "zorbatypes/integer.h"32#include "zorbatypes/integer.h"
3233
=== 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-11 16:49:27 +0000
@@ -25,6 +25,7 @@
25#endif /* DEBUG_TOKENIZER */25#endif /* DEBUG_TOKENIZER */
2626
27#include <zorba/diagnostic_list.h>27#include <zorba/diagnostic_list.h>
28#include <zorba/internal/cxx_util.h>
28#include <zorba/internal/unique_ptr.h>29#include <zorba/internal/unique_ptr.h>
2930
30#include "diagnostics/assert.h"31#include "diagnostics/assert.h"
@@ -32,7 +33,6 @@
32#include "diagnostics/xquery_exception.h"33#include "diagnostics/xquery_exception.h"
33#include "diagnostics/zorba_exception.h"34#include "diagnostics/zorba_exception.h"
34#include "util/ascii_util.h"35#include "util/ascii_util.h"
35#include "util/cxx_util.h"
36#include "util/stl_util.h"36#include "util/stl_util.h"
37#include "util/unicode_util.h"37#include "util/unicode_util.h"
38#include "util/utf8_util.h"38#include "util/utf8_util.h"
3939
=== 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-11 16:49:27 +0000
@@ -19,12 +19,11 @@
1919
20#include <unicode/rbbi.h> /* for RuleBasedBreakIterator */20#include <unicode/rbbi.h> /* for RuleBasedBreakIterator */
2121
22#include <zorba/internal/cxx_util.h>
22#include <zorba/internal/unique_ptr.h>23#include <zorba/internal/unique_ptr.h>
23#include <zorba/locale.h>24#include <zorba/locale.h>
24#include <zorba/tokenizer.h>25#include <zorba/tokenizer.h>
2526
26#include "util/cxx_util.h"
27
28namespace zorba {27namespace zorba {
2928
30///////////////////////////////////////////////////////////////////////////////29///////////////////////////////////////////////////////////////////////////////
3130
=== 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-11 16:49:27 +0000
@@ -15,7 +15,8 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "util/cxx_util.h"18#include <zorba/internal/cxx_util.h>
19
19#include "zorbautils/locale.h"20#include "zorbautils/locale.h"
20#include "zorbautils/mutex.h"21#include "zorbautils/mutex.h"
2122
2223
=== 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-11 16:49:27 +0000
@@ -15,7 +15,8 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "util/cxx_util.h"18#include <zorba/internal/cxx_util.h>
19
19#include "zorbautils/fatal.h"20#include "zorbautils/fatal.h"
20#include "zorbautils/locale.h"21#include "zorbautils/locale.h"
2122
2223
=== 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-11 16:49:27 +0000
@@ -20,7 +20,7 @@
20#include <cstddef> /* for size_t */20#include <cstddef> /* for size_t */
21#include <iterator>21#include <iterator>
2222
23#include "util/cxx_util.h"23#include <zorba/internal/cxx_util.h>
2424
25namespace zorba {25namespace zorba {
2626
2727
=== 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-11 16:49:27 +0000
@@ -21,24 +21,21 @@
21#include <cstring> /* for strcmp(3) */21#include <cstring> /* for strcmp(3) */
22#include <limits>22#include <limits>
2323
24#include <zorba/util/path.h>24#include <zorba/internal/cxx_util.h>
2525
26#include <context/static_context.h>26#include "context/static_context.h"
2727#include "diagnostics/assert.h"
28#include "util/cxx_util.h"28#include "diagnostics/dict.h"
29#include "diagnostics/xquery_diagnostics.h"
30#include "system/globalenv.h"
29#include "util/fs_util.h"31#include "util/fs_util.h"
30#include "util/less.h"32#include "util/less.h"
31#if DEBUG_FT_THESAURUS33#if DEBUG_FT_THESAURUS
32#include "util/oseparator.h"34# include "util/oseparator.h"
33#endif35#endif
34#include "util/utf8_util.h"36#include "util/utf8_util.h"
35#include "diagnostics/assert.h"
36#include "diagnostics/dict.h"
37#include "diagnostics/xquery_diagnostics.h"
38#include "zorbautils/locale.h"37#include "zorbautils/locale.h"
3938
40#include "system/globalenv.h"
41
42#include "decode_base128.h"39#include "decode_base128.h"
43#include "wn_db_segment.h"40#include "wn_db_segment.h"
44#include "wn_synset.h"41#include "wn_synset.h"
4542
=== 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-11 16:49:27 +0000
@@ -18,15 +18,16 @@
18#include <map>18#include <map>
1919
20#include <zorba/config.h>20#include <zorba/config.h>
21#include <zorba/internal/cxx_util.h>
2122
22#include <context/static_context.h>23#include "context/default_url_resolvers.h"
23#include <diagnostics/dict.h>24#include "context/static_context.h"
24#include <diagnostics/xquery_diagnostics.h>25#include "diagnostics/dict.h"
25#include <util/cxx_util.h>26#include "diagnostics/xquery_diagnostics.h"
26#include <util/fs_util.h>27#include "util/fs_util.h"
27#include <util/less.h>28#include "util/less.h"
28#include <util/string_util.h>29#include "util/string_util.h"
29#include <util/uri_util.h>30#include "util/uri_util.h"
3031
31#include "thesaurus.h"32#include "thesaurus.h"
32#ifdef ZORBA_WITH_FILE_ACCESS33#ifdef ZORBA_WITH_FILE_ACCESS
@@ -35,8 +36,6 @@
35#endif36#endif
36#include "thesauri/xqftts_thesaurus.h"37#include "thesauri/xqftts_thesaurus.h"
3738
38#include "context/default_url_resolvers.h"
39
40using namespace std;39using namespace std;
41using namespace zorba::locale;40using namespace zorba::locale;
4241
@@ -112,8 +111,13 @@
112 //111 //
113 zstring t_uri( url_copy );112 zstring t_uri( url_copy );
114 t_uri.replace( 0, 6, "file" ); // xqftts -> file113 t_uri.replace( 0, 6, "file" ); // xqftts -> file
115 zstring const t_path( fs::get_normalized_path( t_uri ) );114 try {
116 return new xqftts::provider( t_path );115 zstring const t_path( fs::normalize_path( t_uri ) );
116 return new xqftts::provider( t_path );
117 }
118 catch ( invalid_argument const &e ) {
119 throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
120 }
117 }121 }
118# endif /* ZORBA_WITH_FILE_ACCESS */122# endif /* ZORBA_WITH_FILE_ACCESS */
119 case thesaurus_impl::wordnet:123 case thesaurus_impl::wordnet:
120124
=== 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-11 16:49:27 +0000
@@ -19,13 +19,12 @@
19#include <sstream>19#include <sstream>
2020
21#include <zorba/diagnostic_list.h>21#include <zorba/diagnostic_list.h>
22#include <zorba/internal/cxx_util.h>
2223
23#include "runtime/json/json.h"24#include "runtime/json/json.h"
24#include "store/api/item_factory.h"25#include "store/api/item_factory.h"
25#include "system/globalenv.h"26#include "system/globalenv.h"
26
27#include "util/ascii_util.h"27#include "util/ascii_util.h"
28#include "util/cxx_util.h"
29#include "util/mem_streambuf.h"28#include "util/mem_streambuf.h"
30#include "util/stream_util.h"29#include "util/stream_util.h"
3130
3231
=== 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-11 16:49:27 +0000
@@ -18,13 +18,13 @@
18#include <sstream>18#include <sstream>
1919
20#include <zorba/diagnostic_list.h>20#include <zorba/diagnostic_list.h>
21#include <zorba/internal/cxx_util.h>
2122
22#include "runtime/json/json.h"23#include "runtime/json/json.h"
23#include "store/api/item_factory.h"24#include "store/api/item_factory.h"
24#include "system/globalenv.h"25#include "system/globalenv.h"
25#include "types/root_typemanager.h"26#include "types/root_typemanager.h"
26#include "util/ascii_util.h"27#include "util/ascii_util.h"
27#include "util/cxx_util.h"
28#include "util/json_parser.h"28#include "util/json_parser.h"
29#include "util/json_util.h"29#include "util/json_util.h"
30#include "util/mem_streambuf.h"30#include "util/mem_streambuf.h"
3131
=== 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-11 16:49:27 +0000
@@ -19,13 +19,13 @@
19#include <string>19#include <string>
2020
21#include <zorba/diagnostic_list.h>21#include <zorba/diagnostic_list.h>
22#include <zorba/internal/cxx_util.h>
2223
23#include "runtime/json/json.h"24#include "runtime/json/json.h"
24#include "store/api/item_factory.h"25#include "store/api/item_factory.h"
25#include "system/globalenv.h"26#include "system/globalenv.h"
26#include "types/root_typemanager.h"27#include "types/root_typemanager.h"
27#include "util/ascii_util.h"28#include "util/ascii_util.h"
28#include "util/cxx_util.h"
29#include "util/indent.h"29#include "util/indent.h"
30#include "util/json_parser.h"30#include "util/json_parser.h"
31#include "util/json_util.h"31#include "util/json_util.h"
3232
=== 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-11 16:49:27 +0000
@@ -47,24 +47,31 @@
47 uri::get_scheme(aUri) == uri::unknown) &&47 uri::get_scheme(aUri) == uri::unknown) &&
48 uri::get_scheme(lBaseUri) == uri::file)48 uri::get_scheme(lBaseUri) == uri::file)
49 {49 {
50 // Ok, we assume it's a filesystem path. First normalize it.50 try
51 zstring lNormalizedPath = fs::get_normalized_path(
52 aUri,
53 zstring(""));
54 // QQQ For now, get_normalized_path() doesn't do what we
55 // want when base URI represents a file. So, when the
56 // normalized path is relative, we pretend it's a relative
57 // URI and resolve it as such.
58 if (fs::is_absolute(lNormalizedPath))
59 {51 {
60 URI::encode_file_URI(lNormalizedPath, *aResult);52 // Ok, we assume it's a filesystem path. First normalize it.
53 zstring lNormalizedPath = fs::normalize_path(
54 aUri,
55 zstring(""));
56 // QQQ For now, normalize_path() doesn't do what we
57 // want when base URI represents a file. So, when the
58 // normalized path is relative, we pretend it's a relative
59 // URI and resolve it as such.
60 if (fs::is_absolute(lNormalizedPath))
61 {
62 URI::encode_file_URI(lNormalizedPath, *aResult);
63 }
64 else
65 {
66 #ifdef WIN32
67 ascii::replace_all(lNormalizedPath, '\\', '/');
68 #endif
69 *aResult = aSctx->resolve_relative_uri(lNormalizedPath, true);
70 }
61 }71 }
62 else72 catch ( std::invalid_argument const &e )
63 {73 {
64#ifdef WIN3274 throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
65 ascii::replace_all(lNormalizedPath, '\\', '/');
66#endif
67 *aResult = aSctx->resolve_relative_uri(lNormalizedPath, true);
68 }75 }
69 }76 }
70 else77 else
@@ -87,6 +94,5 @@
87 }94 }
88}95}
8996
90} /* namespace zorba */97} // namespace zorba
91/* vim:set et sw=2 ts=2: */98/* vim:set et sw=2 ts=2: */
92
9399
=== 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-11 16:49:27 +0000
@@ -21,7 +21,8 @@
21#include <utility> /* for pair */21#include <utility> /* for pair */
22#include <vector>22#include <vector>
2323
24#include "util/cxx_util.h"24#include <zorba/internal/cxx_util.h>
25
25#include "zorbatypes/ft_token.h"26#include "zorbatypes/ft_token.h"
2627
27namespace zorba { 28namespace zorba {
2829
=== 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-11 16:49:27 +0000
@@ -15,8 +15,9 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include <zorba/internal/cxx_util.h>
19
18#include "diagnostics/assert.h"20#include "diagnostics/assert.h"
19#include "util/cxx_util.h"
2021
21#include "naive_ft_token_iterator.h"22#include "naive_ft_token_iterator.h"
2223
2324
=== 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-11 16:49:27 +0000
@@ -21,6 +21,8 @@
2121
22#include <libxml/parser.h>22#include <libxml/parser.h>
2323
24#include <zorba/internal/cxx_util.h>
25
24#include "zorbautils/hashfun.h"26#include "zorbautils/hashfun.h"
25#include "zorbautils/fatal.h"27#include "zorbautils/fatal.h"
26#include "zorbatypes/rchandle.h"28#include "zorbatypes/rchandle.h"
@@ -57,7 +59,6 @@
57#include "pul_primitive_factory.h"59#include "pul_primitive_factory.h"
58#include "tree_id_generator.h"60#include "tree_id_generator.h"
5961
60#include "util/cxx_util.h"
61#include "zorbautils/string_util.h"62#include "zorbautils/string_util.h"
6263
63#ifndef ZORBA_NO_FULL_TEXT64#ifndef ZORBA_NO_FULL_TEXT
6465
=== 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-11 16:49:27 +0000
@@ -17,6 +17,7 @@
17 test_ato_.cpp17 test_ato_.cpp
18 test_base64.cpp18 test_base64.cpp
19 test_base64_streambuf.cpp19 test_base64_streambuf.cpp
20 test_fs_util.cpp
20 test_hashmaps.cpp21 test_hashmaps.cpp
21 test_hexbinary.cpp22 test_hexbinary.cpp
22 test_json_parser.cpp23 test_json_parser.cpp
@@ -26,16 +27,11 @@
26 test_time.cpp27 test_time.cpp
27 test_time_parse.cpp28 test_time_parse.cpp
28 test_uri.cpp29 test_uri.cpp
30 test_utf8_streambuf.cpp
29 test_uuid.cpp31 test_uuid.cpp
30 unit_tests.cpp32 unit_tests.cpp
31 test_utf8_streambuf.cpp
32)33)
3334
34IF (ZORBA_WITH_FILE_ACCESS)
35 LIST (APPEND UNIT_TEST_SRCS
36 test_fs_iterator.cpp)
37ENDIF (ZORBA_WITH_FILE_ACCESS)
38
39IF (NOT ZORBA_NO_FULL_TEXT)35IF (NOT ZORBA_NO_FULL_TEXT)
40 LIST (APPEND UNIT_TEST_SRCS36 LIST (APPEND UNIT_TEST_SRCS
41 test_stemmer.cpp37 test_stemmer.cpp
4238
=== 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-11 16:49:27 +0000
@@ -19,7 +19,8 @@
19#include <stdexcept>19#include <stdexcept>
20#include <string>20#include <string>
2121
22#include "util/cxx_util.h"22#include <zorba/internal/cxx_util.h>
23
23#include "util/string_util.h"24#include "util/string_util.h"
2425
25using namespace std;26using namespace std;
2627
=== 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 @@
1/*
2 * Copyright 2006-2010 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "stdafx.h"
18
19#include <iostream>
20#include <zorba/zorba_exception.h>
21
22#include "util/fs_util.h"
23
24using namespace std;
25using namespace zorba;
26
27///////////////////////////////////////////////////////////////////////////////
28
29namespace zorba {
30namespace UnitTests {
31
32int test_fs_iterator( int argc, char *argv[] ) {
33 int result = 0;
34 try {
35#ifndef WIN32
36 fs::iterator dir_iter( "/" );
37#else
38 fs::iterator dir_iter( "C:\\" );
39#endif /* WIN32 */
40 while ( dir_iter.next() )
41 cout << dir_iter.entry_name() << " (" << dir_iter.entry_type() << ')' << endl;
42 }
43 catch ( ZorbaException const &e ) {
44 cerr << e << endl;
45 result = 2;
46 }
47
48 return result;
49}
50
51} // namespace UnitTests
52} // namespace zorba
53
54/* vim:set et sw=2 ts=2: */
550
=== 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-11 16:49:27 +0000
@@ -0,0 +1,178 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "stdafx.h"
18
19#include <cstring>
20
21#include "util/fs_util.h"
22
23using namespace std;
24using namespace zorba;
25
26struct test {
27 char const *input;
28 char const *expected;
29};
30
31///////////////////////////////////////////////////////////////////////////////
32
33static int failures;
34
35static bool assert_true( int no, char const *expr, int line, bool result ) {
36 if ( !result ) {
37 cout << '#' << no << " FAILED, line " << line << ": " << expr << endl;
38 ++failures;
39 }
40 return result;
41}
42
43static void print_exception( int no, char const *expr, int line,
44 std::exception const &e ) {
45 assert_true( no, expr, line, false );
46 cout << "+ exception: " << e.what() << endl;
47}
48
49#define ASSERT_TRUE( NO, EXPR ) assert_true( NO, #EXPR, __LINE__, !!(EXPR) )
50
51#define ASSERT_NO_EXCEPTION( NO, EXPR ) \
52 try { EXPR; } \
53 catch ( exception const &e ) { print_exception( NO, #EXPR, __LINE__, e ); } \
54 catch ( ... ) { assert_true( NO, #EXPR, __LINE__, false ); }
55
56#define ASSERT_EXCEPTION( NO, EXPR, EXCEPTION ) \
57 try { EXPR; assert_true( NO, #EXPR, __LINE__, false ); } \
58 catch ( EXCEPTION const& ) { } \
59 catch ( ... ) { assert_true( NO, #EXPR, __LINE__, false ); }
60
61///////////////////////////////////////////////////////////////////////////////}
62
63void test_base_name( int no, char const *path, char const *expected ) {
64 ASSERT_TRUE( no, ::strcmp( fs::base_name( path ), expected ) == 0 );
65}
66
67void test_base_name( int no, string const &path, string const &expected ) {
68 ASSERT_TRUE( no, fs::base_name( path ) == expected );
69}
70
71void test_dir_name( int no, char const *path, char const *expected ) {
72 ASSERT_TRUE( no, fs::dir_name( path ) == expected );
73}
74
75void test_dir_name( int no, string const &path, string const &expected ) {
76 ASSERT_TRUE( no, fs::dir_name( path ) == expected );
77}
78
79void test_normalize_path( int no, char const *path, char const *expected ) {
80 ASSERT_TRUE( no, fs::normalize_path( path ) == expected );
81}
82
83///////////////////////////////////////////////////////////////////////////////}
84
85static test const base_name_tests[] = {
86#ifndef WIN32
87 /* 0 */ { "/a/b", "b" },
88 /* 1 */ { "/a" , "a" },
89 /* 2 */ { "/" , "/" },
90 /* 3 */ { "a/b" , "b" },
91 /* 4 */ { "a" , "a" },
92#else
93 /* 0 */ { "C:\\a\\b", "b" },
94 /* 1 */ { "C:\\a" , "a" },
95 /* 2 */ { "C:\\" , "C:\\" },
96 /* 3 */ { "a\\b" , "b" },
97 /* 4 */ { "a" , "a" },
98#endif /* WIN32 */
99 { 0, 0 }
100};
101
102static test const dir_name_tests[] = {
103#ifndef WIN32
104 /* 0 */ { "/a/b", "/a" },
105 /* 1 */ { "/a" , "/" },
106 /* 2 */ { "/" , "/" },
107 /* 3 */ { "a/b" , "a" },
108 /* 4 */ { "a" , "." },
109#else
110 /* 0 */ { "C:\\a\\b", "C:\\a" },
111 /* 1 */ { "C:\\a" , "C:\\" },
112 /* 2 */ { "C:\\" , "C:\\" },
113 /* 3 */ { "a\\b" , "a" },
114 /* 4 */ { "a" , "." },
115#endif /* WIN32 */
116 { 0, 0 }
117};
118
119static test normalize_path_tests[] = {
120#ifndef WIN32
121 /* 0 */ { "/a//b" , "/a/b" },
122 /* 1 */ { "/a///b" , "/a/b" },
123 /* 2 */ { "/a/./b" , "/a/b" },
124 /* 3 */ { "/a/././b" , "/a/b" },
125 /* 4 */ { "/a/b/." , "/a/b" },
126 /* 5 */ { "/a/../b" , "/b" },
127 /* 6 */ { "/a/b/../../c" , "/c" },
128 /* 7 */ { "/a/b/../c/../d" , "/a/d" },
129 /* 8 */ { "/a/b/.." , "/a" },
130 /* 9 */ { "file:///a/b" , "/a/b" },
131 /* 10 */ { "file://localhost/a/b" , "/a/b" },
132 /* 11 */ { "\\a\\b" , "/a/b" },
133#else
134 /* 0 */ { "C:\\a\\\\b" , "C:\\a\\b" },
135 /* 1 */ { "C:\\a\\\\\\b" , "C:\\a\\b" },
136 /* 2 */ { "C:\\a\\.\\b" , "C:\\a\\b" },
137 /* 3 */ { "C:\\a\\.\\.\\b" , "C:\\a\\b" },
138 /* 4 */ { "C:\\a\\b\\." , "C:\\a\\b" },
139 /* 5 */ { "C:\\a\\..\\b" , "C:\\b" },
140 /* 6 */ { "C:\\a\\b\\..\\..\\c" , "C:\\c" },
141 /* 7 */ { "C:\\a\\b\\..\\c\\..\\d" , "C:\\a\\d" },
142 /* 8 */ { "C:\\a\\b\\.." , "C:\\a" },
143 /* 9 */ { "file:///C%3A/a/b" , "C:\\a\\b" },
144 /* 10 */ { "file://localhost/C%3A/a/b" , "C:\\a\\b" },
145 /* 11 */ { "C:/a/b" , "C:\\a\\b" },
146#endif /* WIN32 */
147 { 0, 0 }
148};
149
150namespace zorba {
151namespace UnitTests {
152
153int test_fs_util( int, char*[] ) {
154 int test_no = 0;
155
156 for ( test const *t = base_name_tests; t->input; ++t, ++test_no ) {
157 test_base_name( test_no, t->input, t->expected );
158 test_base_name( test_no, string( t->input ), string( t->expected ) );
159 }
160
161 test_no = 0;
162 for ( test const *t = dir_name_tests; t->input; ++t, ++test_no ) {
163 test_dir_name( test_no, t->input, t->expected );
164 test_dir_name( test_no, string( t->input ), string( t->expected ) );
165 }
166
167 test_no = 0;
168 for ( test const *t = normalize_path_tests; t->input; ++t, ++test_no )
169 test_normalize_path( test_no, t->input, t->expected );
170
171 cout << failures << " test(s) failed\n";
172 return failures ? 1 : 0;
173}
174
175} // namespace UnitTests
176} // namespace zorba
177
178/* vim:set et sw=2 ts=2: */
0179
=== 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-11 16:49:27 +0000
@@ -18,7 +18,8 @@
18#include <iostream>18#include <iostream>
19#include <string>19#include <string>
2020
21#include "util/cxx_util.h"21#include <zorba/internal/cxx_util.h>
22
22#include "util/mem_sizeof.h"23#include "util/mem_sizeof.h"
2324
24using namespace std;25using namespace std;
2526
=== modified file 'src/unit_tests/test_string.cpp'
--- src/unit_tests/test_string.cpp 2013-05-08 01:05:04 +0000
+++ src/unit_tests/test_string.cpp 2013-06-11 16:49:27 +0000
@@ -403,9 +403,9 @@
403 ascii::replace_all( s2, '/', '\\' );403 ascii::replace_all( s2, '/', '\\' );
404 ASSERT_TRUE( s2 == t );404 ASSERT_TRUE( s2 == t );
405405
406 s1 = StringType ("\"");406 s1 = '"';
407 t = StringType("\\\"");407 t = "\\\"";
408 ascii::replace_all( s1, "\"", "\\\"");408 ascii::replace_all( s1, "\"", "\\\"" );
409 ASSERT_TRUE( s1 == t );409 ASSERT_TRUE( s1 == t );
410}410}
411411
412412
=== 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-11 16:49:27 +0000
@@ -31,6 +31,7 @@
31 int test_ato_( int, char*[] );31 int test_ato_( int, char*[] );
32 int test_base64( int, char*[] );32 int test_base64( int, char*[] );
33 int test_base64_streambuf( int, char*[] );33 int test_base64_streambuf( int, char*[] );
34 int test_fs_util( int, char*[] );
34 int test_hashmaps( int argc, char* argv[] );35 int test_hashmaps( int argc, char* argv[] );
35 int test_hexbinary( int argc, char* argv[] );36 int test_hexbinary( int argc, char* argv[] );
3637
@@ -45,10 +46,6 @@
45 int test_time( int, char*[] );46 int test_time( int, char*[] );
46 int test_time_parse( int, char*[] );47 int test_time_parse( int, char*[] );
4748
48#ifdef ZORBA_WITH_FILE_ACCESS
49 int test_fs_iterator( int, char*[] );
50#endif /* ZORBA_WITH_FILE_ACCESS */
51
52#ifndef ZORBA_NO_FULL_TEXT49#ifndef ZORBA_NO_FULL_TEXT
53 int test_stemmer( int, char*[] );50 int test_stemmer( int, char*[] );
54 int test_thesaurus( int, char*[] );51 int test_thesaurus( int, char*[] );
5552
=== 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-11 16:49:27 +0000
@@ -40,11 +40,7 @@
40 libunittests["ato"] = test_ato_;40 libunittests["ato"] = test_ato_;
41 libunittests["base64"] = test_base64;41 libunittests["base64"] = test_base64;
42 libunittests["base64_streambuf"] = test_base64_streambuf;42 libunittests["base64_streambuf"] = test_base64_streambuf;
4343 libunittests["fs_util"] = test_fs_util;
44#ifdef ZORBA_WITH_FILE_ACCESS
45 libunittests["fs_iterator"] = test_fs_iterator;
46#endif /* ZORBA_WITH_FILE_ACCESS */
47
48 libunittests["hashmaps"] = test_hashmaps;44 libunittests["hashmaps"] = test_hashmaps;
49 libunittests["hexbinary"] = test_hexbinary;45 libunittests["hexbinary"] = test_hexbinary;
5046
5147
=== modified file 'src/util/CMakeLists.txt'
--- src/util/CMakeLists.txt 2013-04-12 04:34:41 +0000
+++ src/util/CMakeLists.txt 2013-06-11 16:49:27 +0000
@@ -17,7 +17,6 @@
17 base64_util.cpp17 base64_util.cpp
18 dynamic_bitset.cpp18 dynamic_bitset.cpp
19 error_util.cpp19 error_util.cpp
20 file.cpp
21 fs_util.cpp20 fs_util.cpp
22 hexbinary_util.cpp21 hexbinary_util.cpp
23 indent.cpp22 indent.cpp
2423
=== 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-11 16:49:27 +0000
@@ -25,8 +25,8 @@
25#include <vector>25#include <vector>
2626
27// Zorba27// Zorba
28#include <zorba/internal/cxx_util.h>
28#include <zorba/internal/ztd.h>29#include <zorba/internal/ztd.h>
29#include "cxx_util.h"
30#include "stream_util.h"30#include "stream_util.h"
3131
32namespace zorba {32namespace zorba {
3333
=== 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-11 16:49:27 +0000
@@ -20,9 +20,9 @@
2020
21#ifndef ZORBA_CXX_NULLPTR21#ifndef ZORBA_CXX_NULLPTR
2222
23#include "cxx_util.h"23#include <zorba/internal/cxx_util.h>
2424
25zorba::nullptr_type const zorba_nullptr = { };25zorba::internal::nullptr_type const zorba_nullptr = { };
2626
27#endif /* ZORBA_CXX_NULLPTR */27#endif /* ZORBA_CXX_NULLPTR */
2828
2929
=== 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-11 16:49:27 +0000
@@ -17,7 +17,6 @@
1717
18#include <sstream>18#include <sstream>
1919
20# include <cstring>
21#ifndef WIN3220#ifndef WIN32
22# include <cstdio>21# include <cstdio>
23#else22#else
@@ -25,11 +24,11 @@
25#endif /* WIN32 */24#endif /* WIN32 */
2625
27#include <zorba/internal/unique_ptr.h>26#include <zorba/internal/unique_ptr.h>
27#include <zorba/util/error_util.h>
2828
29#include "diagnostics/dict.h"29#include "diagnostics/dict.h"
30#include "diagnostics/diagnostic.h"30#include "diagnostics/diagnostic.h"
3131
32#include "error_util.h"
33#include "stl_util.h"32#include "stl_util.h"
3433
35namespace zorba {34namespace zorba {
@@ -39,12 +38,8 @@
3938
40////////// exception //////////////////////////////////////////////////////////39////////// exception //////////////////////////////////////////////////////////
4140
42exception::~exception() throw() {41static string make_what( char const *function, char const *path,
43 // out-of-line since it's virtual42 char const *err_string ) {
44}
45
46string exception::make_what( char const *function, char const *path,
47 char const *err_string ) {
48 ostringstream oss;43 ostringstream oss;
49 if ( path && *path )44 if ( path && *path )
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches