Merge lp:~paul-lucas/zorba/bug-1064289 into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Matthias Brantner
Approved revision: 11394
Merged at revision: 11394
Proposed branch: lp:~paul-lucas/zorba/bug-1064289
Merge into: lp:zorba
Diff against target: 380 lines (+102/-52)
9 files modified
ChangeLog (+1/-0)
include/zorba/file.h (+5/-5)
include/zorba/function.h (+4/-0)
include/zorba/util/file.h (+31/-12)
modules/org/expath/ns/file.xq (+17/-4)
modules/org/expath/ns/file.xq.src/file.cpp (+12/-14)
src/api/fileimpl.cpp (+10/-8)
src/api/fileimpl.h (+5/-5)
src/api/functionimpl.cpp (+17/-4)
To merge this branch: bzr merge lp:~paul-lucas/zorba/bug-1064289
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+159904@code.launchpad.net

Commit message

Fixed bug 1064289.
Added "bool follow_symlinks = true" to most File member functions (they should have had it all along).
Added ExternalFunction::getItem() convenience function.

Description of the change

Fixed bug 1064289.
Added "bool follow_symlinks = true" to most File member functions (they should have had it all along).
Added ExternalFunction::getItem() convenience function.

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
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1064289-2013-04-19T22-31-50.875Z 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) :
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-1064289-2013-04-19T23-18-43.694Z 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 'ChangeLog'
2--- ChangeLog 2013-04-19 04:07:25 +0000
3+++ ChangeLog 2013-04-19 22:28:26 +0000
4@@ -72,6 +72,7 @@
5 * Fixed bug #1023168 (Non-single-char-escapes in regex character ranges not
6 caught)
7 * Throw XQST0048 for groupby clause, as specified by XQuery 3.0.
8+ * Fixed bug #1064289 (file module cannot delete broken symbolic links)
9 * Fixed bug in raising XQTY0086 (copying of namespace-sensitive values during
10 node construction).
11 * Fixed bug #866874 (regex "range subtraction" not supported for ICU)
12
13=== modified file 'include/zorba/file.h'
14--- include/zorba/file.h 2013-02-07 17:24:36 +0000
15+++ include/zorba/file.h 2013-04-19 22:28:26 +0000
16@@ -70,12 +70,12 @@
17 virtual const std::string getFilePath() const = 0;
18 virtual const std::string getFileUri() const = 0;
19
20- virtual bool isDirectory() const = 0;
21- virtual bool isFile() const = 0;
22+ virtual bool isDirectory( bool follow_symlinks = true ) const = 0;
23+ virtual bool isFile( bool follow_symlinks = true ) const = 0;
24 virtual bool isLink() const = 0;
25- virtual bool isVolume() const = 0;
26- virtual bool isInvalid() const = 0;
27- virtual bool exists() const = 0;
28+ virtual bool isVolume( bool follow_symlinks = true ) const = 0;
29+ virtual bool isInvalid() const = 0; // deprecated
30+ virtual bool exists( bool follow_symlinks = true ) const = 0;
31
32 virtual void remove() = 0;
33 virtual bool create() = 0;
34
35=== modified file 'include/zorba/function.h'
36--- include/zorba/function.h 2013-02-07 17:24:36 +0000
37+++ include/zorba/function.h 2013-04-19 22:28:26 +0000
38@@ -170,6 +170,10 @@
39 */
40 virtual bool
41 isContextual() const = 0;
42+
43+protected:
44+ Item
45+ getItem( Arguments_t const &args, unsigned pos ) const;
46 };
47
48
49
50=== modified file 'include/zorba/util/file.h'
51--- include/zorba/util/file.h 2013-03-06 02:54:03 +0000
52+++ include/zorba/util/file.h 2013-04-19 22:28:26 +0000
53@@ -1,12 +1,12 @@
54 /*
55 * Copyright 2006-2008 The FLWOR Foundation.
56- *
57+ *
58 * Licensed under the Apache License, Version 2.0 (the "License");
59 * you may not use this file except in compliance with the License.
60 * You may obtain a copy of the License at
61- *
62+ *
63 * http://www.apache.org/licenses/LICENSE-2.0
64- *
65+ *
66 * Unless required by applicable law or agreed to in writing, software
67 * distributed under the License is distributed on an "AS IS" BASIS,
68 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
69@@ -57,15 +57,34 @@
70 public: // common methods
71 void set_path(std::string const& _path ) { *((filesystem_path *) this) = _path; }
72 void set_filetype(filetype) { /* do nothing */ } // deprecated
73- filetype get_filetype() const { return do_stat(); }
74-
75- bool is_directory() const { return do_stat() == type_directory; }
76- bool is_file() const { return do_stat() == type_file; }
77- bool is_link() const { return do_stat( false ) == type_link; }
78- bool is_volume() const { return do_stat() == type_volume; }
79-
80- bool is_invalid() const { return false; } // deprecated
81- bool exists() const { return do_stat() != type_non_existent; }
82+
83+ filetype get_filetype( bool follow_symlinks = true ) const {
84+ return do_stat( follow_symlinks );
85+ }
86+
87+ bool is_directory( bool follow_symlinks = true ) const {
88+ return do_stat( follow_symlinks ) == type_directory;
89+ }
90+
91+ bool is_file( bool follow_symlinks = true ) const {
92+ return do_stat( follow_symlinks ) == type_file;
93+ }
94+
95+ bool is_link() const {
96+ return do_stat( false ) == type_link;
97+ }
98+
99+ bool is_volume( bool follow_symlinks = true ) const {
100+ return do_stat( follow_symlinks ) == type_volume;
101+ }
102+
103+ bool is_invalid() const { // deprecated
104+ return false;
105+ }
106+
107+ bool exists( bool follow_symlinks = true ) const {
108+ return do_stat( follow_symlinks ) != type_non_existent;
109+ }
110
111 time_t lastModified() const;
112
113
114=== modified file 'modules/org/expath/ns/file.xq'
115--- modules/org/expath/ns/file.xq 2013-03-06 04:04:43 +0000
116+++ modules/org/expath/ns/file.xq 2013-04-19 22:28:26 +0000
117@@ -227,7 +227,7 @@
118 $path as xs:string
119 ) as empty-sequence()
120 {
121- if (file:exists($path)) then
122+ if (file:exists($path,false())) then
123 if (not(file:is-symlink($path)) and file:is-directory($path)) then
124 file:delete-directory-impl($path)
125 else
126@@ -276,13 +276,26 @@
127 : Tests if a path/URI is already used in the file system.
128 :
129 : @param $path The path/URI to test.
130+ : @param $follow-symlinks if <code>true</code>, follows symbolic links.
131+ : @return true if <code>$path</code> points to an existing file system item.
132+ :)
133+declare %an:nondeterministic function file:exists(
134+ $path as xs:string, $follow-symlinks as xs:boolean
135+) as xs:boolean external;
136+
137+(:~
138+ : Tests if a path/URI is already used in the file system.
139+ :
140+ : @param $path The path/URI to test.
141 : @return true if <code>$path</code> points to an existing file system item;
142- : for symbolic links, retuns true if the symbolic link itself exists and not
143- : whether the linked-to item exists.
144+ : for symbolic links, retuns true if the linked-to item exists.
145 :)
146 declare %an:nondeterministic function file:exists(
147 $path as xs:string
148-) as xs:boolean external;
149+) as xs:boolean
150+{
151+ file:exists($path,true())
152+};
153
154 (:~
155 : Tests if a path/URI points to a directory. On Unix-based systems, the root
156
157=== modified file 'modules/org/expath/ns/file.xq.src/file.cpp'
158--- modules/org/expath/ns/file.xq.src/file.cpp 2013-03-13 16:17:38 +0000
159+++ modules/org/expath/ns/file.xq.src/file.cpp 2013-04-19 22:28:26 +0000
160@@ -60,7 +60,7 @@
161 // actual mkdir
162 try {
163 lFile->mkdir(true);
164- } catch (ZorbaException& ze) {
165+ } catch (ZorbaException const& ze) {
166 std::stringstream lSs;
167 lSs << "An unknown error occured: " << ze.what() << "Can not create directory";
168 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
169@@ -94,14 +94,14 @@
170 File_t lFile = File::createFile(lFileStr.c_str());
171
172 // precondition
173- if (!lFile->exists()) {
174+ if (!lFile->exists( false )) {
175 raiseFileError("FOFL0001", "A file or directory does not exist at this path", lFile->getFilePath());
176 }
177
178 // actual remove
179 try {
180 lFile->remove();
181- } catch (ZorbaException& ze) {
182+ } catch (ZorbaException const& ze) {
183 std::stringstream lSs;
184 lSs << "An unknown error occured: " << ze.what() << "Can not delete file";
185 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
186@@ -111,7 +111,7 @@
187 }
188
189 // postcondition
190- if (lFile->exists()) {
191+ if (lFile->exists( false )) {
192 raiseFileError("FOFL9999", "The file at this path could not be deleted", lFile->getFilePath());
193 }
194
195@@ -153,7 +153,7 @@
196 *lInStream.release(), &FileModule::streamReleaser, true
197 );
198
199- } catch (ZorbaException& ze) {
200+ } catch (ZorbaException const& ze) {
201 std::stringstream lSs;
202 lSs << "An unknown error occured: " << ze.what() << "Can not read file";
203 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
204@@ -353,13 +353,11 @@
205 const StaticContext* aSctxCtx,
206 const DynamicContext* aDynCtx) const
207 {
208- bool lFileExists = false;
209- String lFileStr = getFilePathString(aArgs, 0);
210+ String const lFileStr = getFilePathString(aArgs, 0);
211+ bool const lFollowSymlinks = getItem(aArgs, 1).getBooleanValue();
212
213 File_t lFile = File::createFile(lFileStr.c_str());
214- if (lFile->exists()) {
215- lFileExists = true;
216- }
217+ bool const lFileExists = lFile->exists(lFollowSymlinks);
218
219 return ItemSequence_t(new SingletonItemSequence(
220 theModule->getItemFactory()->createBoolean(lFileExists)));
221@@ -504,7 +502,7 @@
222 lInStream.close();
223 lOutStream.close();
224
225- } catch (ZorbaException& ze) {
226+ } catch (ZorbaException const& ze) {
227 std::stringstream lSs;
228 lSs << "An unknown error occured: " << ze.what() << "Can not copy file";
229 raiseFileError("FOFL9999", lSs.str(), lSrcFile->getFilePath());
230@@ -541,7 +539,7 @@
231 try {
232 DirectoryIterator_t lIter = lFile->files();
233 return ItemSequence_t(new IteratorBackedItemSequence(lIter, theModule->getItemFactory()));
234- } catch (ZorbaException& ze) {
235+ } catch (ZorbaException const& ze) {
236 std::stringstream lSs;
237 lSs << "An unknown error occured: " << ze.what() << "Can not list directory";
238 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
239@@ -641,7 +639,7 @@
240 lT.tm_min,
241 lT.tm_sec,
242 gmtOffset)));
243- } catch (ZorbaException& ze) {
244+ } catch (ZorbaException const& ze) {
245 std::stringstream lSs;
246 lSs << "An unknown error occured: " << ze.what() << "Can not retrieve the last modification timestamp of";
247 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
248@@ -696,7 +694,7 @@
249 File::FileSize_t lFs = -1;
250 try {
251 lFs = lFile->getSize();
252- } catch (ZorbaException& ze) {
253+ } catch (ZorbaException const& ze) {
254 std::stringstream lSs;
255 lSs << "An unknown error occured: " << ze.what() << "Can not retrieve the file size of";
256 raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
257
258=== modified file 'src/api/fileimpl.cpp'
259--- src/api/fileimpl.cpp 2013-02-07 17:24:36 +0000
260+++ src/api/fileimpl.cpp 2013-04-19 22:28:26 +0000
261@@ -139,24 +139,26 @@
262 }
263
264 bool
265-FileImpl::isDirectory() const
266+FileImpl::isDirectory( bool follow_symlinks ) const
267 {
268 bool lResult = false;
269
270 ZORBA_TRY
271- lResult = theInternalFile->is_directory() || theInternalFile->is_volume() || theInternalFile->is_root();
272+ lResult = theInternalFile->is_directory( follow_symlinks )
273+ || theInternalFile->is_volume( follow_symlinks )
274+ || theInternalFile->is_root();
275 ZORBA_CATCH
276
277 return lResult;
278 }
279
280 bool
281-FileImpl::isFile() const
282+FileImpl::isFile( bool follow_symlinks ) const
283 {
284 bool lResult = false;
285
286 ZORBA_TRY
287- lResult = theInternalFile->is_file() || theInternalFile->is_link();
288+ lResult = theInternalFile->is_file( follow_symlinks ) || theInternalFile->is_link();
289 ZORBA_CATCH
290
291 return lResult;
292@@ -175,12 +177,12 @@
293 }
294
295 bool
296-FileImpl::isVolume() const
297+FileImpl::isVolume( bool follow_symlinks ) const
298 {
299 bool lResult = false;
300
301 ZORBA_TRY
302- lResult = theInternalFile->is_volume();
303+ lResult = theInternalFile->is_volume( follow_symlinks );
304 ZORBA_CATCH
305
306 return lResult;
307@@ -199,12 +201,12 @@
308 }
309
310 bool
311-FileImpl::exists() const
312+FileImpl::exists( bool follow_symlinks ) const
313 {
314 bool lResult = false;
315
316 ZORBA_TRY
317- lResult = theInternalFile->exists();
318+ lResult = theInternalFile->exists( follow_symlinks );
319 ZORBA_CATCH
320
321 return lResult;
322
323=== modified file 'src/api/fileimpl.h'
324--- src/api/fileimpl.h 2013-02-07 17:24:36 +0000
325+++ src/api/fileimpl.h 2013-04-19 22:28:26 +0000
326@@ -63,12 +63,12 @@
327 const std::string getFilePath() const;
328 const std::string getFileUri() const;
329
330- bool isDirectory() const;
331- bool isFile() const;
332+ bool isDirectory( bool follow_symlinks = true ) const;
333+ bool isFile( bool follow_symlinks = true ) const;
334 bool isLink() const;
335- bool isVolume() const;
336- bool isInvalid() const;
337- bool exists() const;
338+ bool isVolume( bool follow_symlinks = true ) const;
339+ bool isInvalid() const; // deprecated
340+ bool exists( bool follow_symlinks = true ) const;
341
342 void remove();
343 bool create();
344
345=== modified file 'src/api/functionimpl.cpp'
346--- src/api/functionimpl.cpp 2013-02-07 17:24:36 +0000
347+++ src/api/functionimpl.cpp 2013-04-19 22:28:26 +0000
348@@ -25,8 +25,9 @@
349 #include "annotations/annotations.h"
350 #include "api/annotationimpl.h"
351
352-namespace zorba
353-{
354+namespace zorba {
355+
356+///////////////////////////////////////////////////////////////////////////////
357
358 bool FunctionImpl::isUpdating() const
359 {
360@@ -143,6 +144,18 @@
361 return static_cast<function*>(theFunction)->isBuiltin();
362 }
363
364-
365-} /* namespace zorba */
366+///////////////////////////////////////////////////////////////////////////////
367+
368+Item ExternalFunction::getItem( Arguments_t const &args, unsigned pos ) const {
369+ Iterator_t i = args[ pos ]->getIterator();
370+ Item item;
371+ i->open();
372+ i->next( item );
373+ i->close();
374+ return item;
375+}
376+
377+///////////////////////////////////////////////////////////////////////////////
378+
379+} // namespace zorba
380 /* vim:set et sw=2 ts=2: */

Subscribers

People subscribed via source and target branches