aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/importer.cc
diff options
context:
space:
mode:
authorkenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-04-25 02:53:47 +0000
committerkenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-04-25 02:53:47 +0000
commitd37d46dfbcedadeb439ad0367f8afcf8867dca43 (patch)
treeb896df229f7c671637924c156d5a759ba50a3190 /src/google/protobuf/compiler/importer.cc
parent709ea28f3264aa5632e5577a4080671173fc6166 (diff)
downloadprotobuf-d37d46dfbcedadeb439ad0367f8afcf8867dca43.tar.gz
protobuf-d37d46dfbcedadeb439ad0367f8afcf8867dca43.tar.bz2
protobuf-d37d46dfbcedadeb439ad0367f8afcf8867dca43.zip
Integrate recent changes from Google-internal code tree. See CHANGES.txt
for details.
Diffstat (limited to 'src/google/protobuf/compiler/importer.cc')
-rw-r--r--src/google/protobuf/compiler/importer.cc34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc
index 30e106e8..8a07dfc4 100644
--- a/src/google/protobuf/compiler/importer.cc
+++ b/src/google/protobuf/compiler/importer.cc
@@ -387,9 +387,22 @@ DiskSourceTree::DiskFileToVirtualFile(
return SUCCESS;
}
+bool DiskSourceTree::VirtualFileToDiskFile(const string& virtual_file,
+ string* disk_file) {
+ scoped_ptr<io::ZeroCopyInputStream> stream(OpenVirtualFile(virtual_file,
+ disk_file));
+ return stream != NULL;
+}
+
io::ZeroCopyInputStream* DiskSourceTree::Open(const string& filename) {
- if (filename != CanonicalizePath(filename) ||
- ContainsParentReference(filename)) {
+ return OpenVirtualFile(filename, NULL);
+}
+
+io::ZeroCopyInputStream* DiskSourceTree::OpenVirtualFile(
+ const string& virtual_file,
+ string* disk_file) {
+ if (virtual_file != CanonicalizePath(virtual_file) ||
+ ContainsParentReference(virtual_file)) {
// We do not allow importing of paths containing things like ".." or
// consecutive slashes since the compiler expects files to be uniquely
// identified by file name.
@@ -397,16 +410,21 @@ io::ZeroCopyInputStream* DiskSourceTree::Open(const string& filename) {
}
for (int i = 0; i < mappings_.size(); i++) {
- string disk_file;
- if (ApplyMapping(filename, mappings_[i].virtual_path,
- mappings_[i].disk_path, &disk_file)) {
- io::ZeroCopyInputStream* stream = OpenDiskFile(disk_file);
- if (stream != NULL) return stream;
+ string temp_disk_file;
+ if (ApplyMapping(virtual_file, mappings_[i].virtual_path,
+ mappings_[i].disk_path, &temp_disk_file)) {
+ io::ZeroCopyInputStream* stream = OpenDiskFile(temp_disk_file);
+ if (stream != NULL) {
+ if (disk_file != NULL) {
+ *disk_file = temp_disk_file;
+ }
+ return stream;
+ }
if (errno == EACCES) {
// The file exists but is not readable.
// TODO(kenton): Find a way to report this more nicely.
- GOOGLE_LOG(WARNING) << "Read access is denied for file: " << disk_file;
+ GOOGLE_LOG(WARNING) << "Read access is denied for file: " << temp_disk_file;
return NULL;
}
}