Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Ghislain Fourny
Approved revision: 11247
Merged at revision: 11514
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 209 lines (+44/-36)
8 files modified
include/zorba/util/fs_util.h (+7/-3)
modules/org/expath/ns/file.xq.src/file.cpp (+1/-1)
src/diagnostics/diagnostic_en.xml (+5/-5)
src/diagnostics/dict_XX_cpp.xq (+3/-16)
src/diagnostics/pregenerated/dict_en.cpp (+3/-3)
src/diagnostics/pregenerated/dict_zed_keys.h (+2/-2)
src/util/error_util.cpp (+2/-2)
src/util/fs_util.cpp (+21/-4)
To merge this branch: bzr merge lp:~paul-lucas/zorba/pjl-misc
Reviewer Review Type Date Requested Status
Ghislain Fourny Approve
Paul J. Lucas Approve
Review via email: mp+169270@code.launchpad.net

Commit message

file:create-directory() now creates intermediate directories.
(Also fixed error messages off-by-one bug in error_util.)

Description of the change

file:create-directory() now creates intermediate directories.
(Also fixed error messages off-by-one bug in error_util.)

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Ghislain Fourny (gislenius) wrote :

It works, thanks!

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 pjl-misc-2013-06-14T10-24-56.613Z 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
1=== modified file 'include/zorba/util/fs_util.h'
2--- include/zorba/util/fs_util.h 2013-06-11 01:26:43 +0000
3+++ include/zorba/util/fs_util.h 2013-06-13 18:26:28 +0000
4@@ -124,22 +124,26 @@
5 * Creates a directory.
6 *
7 * @param path The full path of the directory to create.
8+ * @param intermediate If \c true, any non-existent directories along \a path
9+ * are also created.
10 * @throws fs::exception if the creation fails.
11 */
12 ZORBA_DLL_PUBLIC
13-void mkdir( char const *path );
14+void mkdir( char const *path, bool intermediate = false );
15
16 /**
17 * Creates a directory.
18 *
19 * @tparam PathStringType The \a path string type.
20 * @param path The full path of the directory to create.
21+ * @param intermediate If \c true, any non-existent directories along \a path
22+ * are also created.
23 * @throws fs::exception if the creation fails.
24 */
25 template<class PathStringType> inline
26 typename std::enable_if<ZORBA_HAS_C_STR(PathStringType),void>::type
27-mkdir( PathStringType const &path ) {
28- mkdir( path.c_str() );
29+mkdir( PathStringType const &path, bool intermediate = false ) {
30+ mkdir( path.c_str(), intermediate );
31 }
32
33 #endif /* ZORBA_WITH_FILE_ACCESS */
34
35=== modified file 'modules/org/expath/ns/file.xq.src/file.cpp'
36--- modules/org/expath/ns/file.xq.src/file.cpp 2013-06-13 14:10:48 +0000
37+++ modules/org/expath/ns/file.xq.src/file.cpp 2013-06-13 18:26:28 +0000
38@@ -78,7 +78,7 @@
39 fs::type const fs_type = fs::get_type( path );
40 if ( !fs_type )
41 try {
42- fs::mkdir( path );
43+ fs::mkdir( path, true );
44 }
45 catch ( std::exception const &e ) {
46 throw raiseFileError( "FOFL9999", e.what(), path );
47
48=== modified file 'src/diagnostics/diagnostic_en.xml'
49--- src/diagnostics/diagnostic_en.xml 2013-06-04 14:09:51 +0000
50+++ src/diagnostics/diagnostic_en.xml 2013-06-13 18:26:28 +0000
51@@ -3718,7 +3718,7 @@
52 </entry>
53
54 <entry key="ErrorCodeMessage_12">
55- <value>error $2: $3</value>
56+ <value>error $1: $2</value>
57 </entry>
58
59 <entry key="ExpectedNumericOrDurationType">
60@@ -3765,12 +3765,12 @@
61 <value>full-text was not enabled in this build</value>
62 </entry>
63
64- <entry key="FunctionFailedErrorCodeMessage_234">
65- <value>$2 failed (error $3): $4</value>
66+ <entry key="FunctionFailedErrorCodeMessage_123">
67+ <value>$1 failed (error $2): $3</value>
68 </entry>
69
70- <entry key="FunctionFailed_23o">
71- <value>$2 failed${: 3}</value>
72+ <entry key="FunctionFailed_12o">
73+ <value>$1 failed${: 2}</value>
74 </entry>
75
76 <entry key="FunctionUndeclared_3">
77
78=== modified file 'src/diagnostics/dict_XX_cpp.xq'
79--- src/diagnostics/dict_XX_cpp.xq 2013-02-07 17:24:36 +0000
80+++ src/diagnostics/dict_XX_cpp.xq 2013-06-13 18:26:28 +0000
81@@ -25,22 +25,9 @@
82 return $entry/@code
83 case $e as element(entry)
84 return
85- (
86- (: raise an error if sub-message contains $1 as parameter :)
87- if ( contains ( $e/value, "$1" ) )
88- then
89- error(
90- fn:QName("http://www.zorba-xquery.com/error", "submessage"),
91- concat(
92- "sub-entry must not contain parameter named $1: ", $e/value
93- )
94- )
95- else
96- (),
97- if ( $e/parent::diagnostic )
98- then concat( "~", $e/parent::diagnostic/@code, "_", $entry/@key )
99- else concat( "~", $entry/@key )
100- )
101+ if ( $e/parent::diagnostic )
102+ then concat( "~", $e/parent::diagnostic/@code, "_", $entry/@key )
103+ else concat( "~", $entry/@key )
104 default
105 return error()
106 let $value := replace( replace( $entry/value, '\\', '\\\\' ), '"', '\\"' )
107
108=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
109--- src/diagnostics/pregenerated/dict_en.cpp 2013-06-04 14:09:51 +0000
110+++ src/diagnostics/pregenerated/dict_en.cpp 2013-06-13 18:26:28 +0000
111@@ -620,7 +620,7 @@
112 { "~EmptySeqNoFnRemoveArg", "empty sequence not allowed as 2nd argument of fn:remove()" },
113 { "~EmptySeqNoSearchItem", "empty sequence not allowed as search item of fn:index-of()" },
114 { "~EmptySequence", "empty sequence" },
115- { "~ErrorCodeMessage_12", "error $2: $3" },
116+ { "~ErrorCodeMessage_12", "error $1: $2" },
117 { "~ExpectedNumericOrDurationType", "expected numeric or duration type" },
118 { "~ExpectedNumericType", "expected numeric type" },
119 { "~ExpectedType_5", "expected type \"$5\"" },
120@@ -681,8 +681,8 @@
121 { "~FnNilledArgNotNode", "fn:nilled() argument not a node" },
122 { "~FnOnlyInXQueryVersion_3", "function only available in XQuery $3" },
123 { "~FullTextNotEnabled", "full-text was not enabled in this build" },
124- { "~FunctionFailedErrorCodeMessage_234", "$2 failed (error $3): $4" },
125- { "~FunctionFailed_23o", "$2 failed${: 3}" },
126+ { "~FunctionFailedErrorCodeMessage_123", "$1 failed (error $2): $3" },
127+ { "~FunctionFailed_12o", "$1 failed${: 2}" },
128 { "~FunctionUndeclared_3", "function with arity $3 not declared" },
129 { "~GoodValuesAreUTF8", "valid values are: UTF-8, UTF-16" },
130 { "~GoodValuesAreXMLEtc", "valid values are: xml, html, xhtml, text, binary, json, jsoniq" },
131
132=== modified file 'src/diagnostics/pregenerated/dict_zed_keys.h'
133--- src/diagnostics/pregenerated/dict_zed_keys.h 2013-05-31 23:44:41 +0000
134+++ src/diagnostics/pregenerated/dict_zed_keys.h 2013-06-13 18:26:28 +0000
135@@ -245,8 +245,8 @@
136 #define ZED_FnNilledArgNotNode "~FnNilledArgNotNode"
137 #define ZED_FnOnlyInXQueryVersion_3 "~FnOnlyInXQueryVersion_3"
138 #define ZED_FullTextNotEnabled "~FullTextNotEnabled"
139-#define ZED_FunctionFailedErrorCodeMessage_234 "~FunctionFailedErrorCodeMessage_234"
140-#define ZED_FunctionFailed_23o "~FunctionFailed_23o"
141+#define ZED_FunctionFailedErrorCodeMessage_123 "~FunctionFailedErrorCodeMessage_123"
142+#define ZED_FunctionFailed_12o "~FunctionFailed_12o"
143 #define ZED_FunctionUndeclared_3 "~FunctionUndeclared_3"
144 #define ZED_GoodValuesAreUTF8 "~GoodValuesAreUTF8"
145 #define ZED_GoodValuesAreXMLEtc "~GoodValuesAreXMLEtc"
146
147=== modified file 'src/util/error_util.cpp'
148--- src/util/error_util.cpp 2013-05-31 14:36:28 +0000
149+++ src/util/error_util.cpp 2013-06-13 18:26:28 +0000
150@@ -67,7 +67,7 @@
151 if ( function && *function ) {
152 using namespace internal::diagnostic;
153 parameters::value_type result =
154- diagnostic::dict::lookup( ZED( FunctionFailed_23o ) );
155+ diagnostic::dict::lookup( ZED( FunctionFailed_12o ) );
156 parameters const params( ERROR_PARAMS( function, err_string ) );
157 params.substitute( &result );
158 return result;
159@@ -82,7 +82,7 @@
160 parameters::value_type result;
161 if ( function && *function ) {
162 result = diagnostic::dict::lookup(
163- ZED( FunctionFailedErrorCodeMessage_234 )
164+ ZED( FunctionFailedErrorCodeMessage_123 )
165 );
166 params = ERROR_PARAMS( function, code, err_string );
167 } else {
168
169=== modified file 'src/util/fs_util.cpp'
170--- src/util/fs_util.cpp 2013-06-11 01:33:32 +0000
171+++ src/util/fs_util.cpp 2013-06-13 18:26:28 +0000
172@@ -382,16 +382,33 @@
173
174 #ifdef ZORBA_WITH_FILE_ACCESS
175
176-void mkdir( char const *path ) {
177+void mkdir_impl( char const *path, bool ignore_exists = false ) {
178 #ifndef WIN32
179- if ( ::mkdir( path, 0755 ) != 0 )
180+ if ( ::mkdir( path, 0755 ) != 0 &&
181+ !(ignore_exists && (errno == EEXIST || errno == EISDIR)) ) {
182 throw fs::exception( "mkdir()", path );
183+ }
184 #else
185 WCHAR wpath[ MAX_PATH ];
186 win32::to_wchar( path, wpath );
187- if ( !::CreateDirectory( wpath, NULL ) )
188+ if ( !::CreateDirectory( wpath, NULL ) &&
189+ !(ignore_exists && ::GetLastError() == ERROR_ALREADY_EXISTS) ) {
190 throw fs::exception( "CreateDirectory()", path );
191-#endif
192+ }
193+#endif /* WIN32 */
194+}
195+
196+void mkdir( char const *path, bool intermediate ) {
197+ if ( !intermediate )
198+ mkdir_impl( path );
199+ else {
200+ string const dir( dir_name( path ) );
201+ if ( dir != path )
202+ mkdir( dir, true );
203+ else
204+ mkdir_impl( dir.c_str(), true );
205+ mkdir_impl( path, true );
206+ }
207 }
208
209 string normalize_path( char const *path, char const *base ) {

Subscribers

People subscribed via source and target branches