summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2015-07-06 15:21:45 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2015-07-06 15:21:46 +0000
commita3c31dfd721e54bd00fa7bfe218a69e5483a5a5d (patch)
tree9360aad650e907b156955ca06cf8faf932ccb52e
parentd5c5ea39775276e38df8b5981a8423777254e098 (diff)
parentb73f1f580d50b5f0792ec99c22a0eb4b355d7012 (diff)
Merge "ART: Unlink old file in OS::CreateEmptyFile"
-rw-r--r--runtime/os.h3
-rw-r--r--runtime/os_linux.cc4
2 files changed, 6 insertions, 1 deletions
diff --git a/runtime/os.h b/runtime/os.h
index 6248d5fc14..befe2e808a 100644
--- a/runtime/os.h
+++ b/runtime/os.h
@@ -35,7 +35,8 @@ class OS {
// Open an existing file with read/write access.
static File* OpenFileReadWrite(const char* name);
- // Create an empty file with read/write access.
+ // Create an empty file with read/write access. This is a *new* file, that is, if the file
+ // already exists, it is *not* overwritten, but unlinked, and a new inode will be used.
static File* CreateEmptyFile(const char* name);
// Open a file with the specified open(2) flags.
diff --git a/runtime/os_linux.cc b/runtime/os_linux.cc
index 22827891b0..675699daea 100644
--- a/runtime/os_linux.cc
+++ b/runtime/os_linux.cc
@@ -36,6 +36,10 @@ File* OS::OpenFileReadWrite(const char* name) {
}
File* OS::CreateEmptyFile(const char* name) {
+ // In case the file exists, unlink it so we get a new file. This is necessary as the previous
+ // file may be in use and must not be changed.
+ unlink(name);
+
return OpenFileWithFlags(name, O_RDWR | O_CREAT | O_TRUNC);
}