summaryrefslogtreecommitdiffstats
path: root/src/uri.cpp
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2014-01-26 17:19:47 +0000
committerMartin Owens <doctormo@gmail.com>2014-01-26 17:19:47 +0000
commit7455f1a259ce28ee56866b5cde06e79be4cfaf97 (patch)
tree5c10c6096fac9f5ff169abbc32133bc3b3dc1094 /src/uri.cpp
parentA partial refactor of sp-image.cpp, expect more. (diff)
downloadinkscape-7455f1a259ce28ee56866b5cde06e79be4cfaf97.tar.gz
inkscape-7455f1a259ce28ee56866b5cde06e79be4cfaf97.zip
Check file existance and clean up memory issues thanks to KK and Johan
(bzr r12979)
Diffstat (limited to 'src/uri.cpp')
-rw-r--r--src/uri.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/uri.cpp b/src/uri.cpp
index 8d0e49139..89f6f33e4 100644
--- a/src/uri.cpp
+++ b/src/uri.cpp
@@ -135,14 +135,25 @@ gchar *URI::to_native_filename(gchar const* uri) throw(BadURIException)
filename = tmp.toNativeFilename();
return filename;
}
-
+/*
+ * Returns the absolute path to an existing file referenced in this URI,
+ * if the uri is data, the path is empty or the file doesn't exist, then
+ * an empty string is returned.
+ *
+ * Does not check if the returned path is the local document's path (local)
+ * and thus redundent. Caller is expected to check against the document's path.
+ */
const std::string URI::getFullPath(std::string const base) const {
std::string path = std::string(_impl->getPath());
// Calculate the absolute path from an available base
- if(!path.empty() && !base.empty() && path.compare(0, 1, "/") != 0) {
+ if(!base.empty() && !path.empty() && path[0] != '/') {
path = Glib::build_filename(base, path);
}
- // TODO: Check existance of file here
+ // Check the existance of the file
+ if(! g_file_test(path.c_str(), G_FILE_TEST_EXISTS)
+ || g_file_test(path.c_str(), G_FILE_TEST_IS_DIR) ) {
+ path.clear();
+ }
return path;
}