Index: runtime/bin/file_linux.cc |
diff --git a/runtime/bin/file_linux.cc b/runtime/bin/file_linux.cc |
index 409f31c8800b4f5e0eee3d3c790a71d101729d9e..21e6825da5a573486dbb4958038f84a8881854da 100644 |
--- a/runtime/bin/file_linux.cc |
+++ b/runtime/bin/file_linux.cc |
@@ -105,6 +105,13 @@ off_t File::Length() { |
File* File::Open(const char* name, FileOpenMode mode) { |
+ struct stat st; |
+ if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
Mads Ager (google)
2012/03/13 10:56:17
Why do you need this? Isn't the error code from op
Søren Gjesse
2012/03/13 12:39:49
This is to avoid opening non-regular files. Before
|
+ if (!S_ISREG(st.st_mode)) { |
+ errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
+ return false; |
Mads Ager (google)
2012/03/13 10:56:17
false -> NULL
Søren Gjesse
2012/03/13 12:39:49
Good catch, done.
|
+ } |
+ } |
int flags = O_RDONLY; |
if ((mode & kWrite) != 0) { |
flags = (O_RDWR | O_CREAT); |
@@ -178,6 +185,15 @@ char* File::GetCanonicalPath(const char* pathname) { |
char* File::GetContainingDirectory(char* pathname) { |
+ struct stat st; |
+ if (TEMP_FAILURE_RETRY(stat(pathname, &st)) == 0) { |
Mads Ager (google)
2012/03/13 10:56:17
Similarly here, don't we get a good enough error m
Søren Gjesse
2012/03/13 12:39:49
As for open above we used to have an exists check
|
+ if (!S_ISREG(st.st_mode)) { |
+ errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
+ return NULL; |
+ } |
+ } else { |
+ return NULL; |
+ } |
char* path = NULL; |
do { |
path = dirname(pathname); |