Add kTruncate in FileBase. BUG=6841435.
And remove O_TRUNC from the default flags to OutputFile.
Change-Id: Id2ff6d5bac319d8be498e438eb3ef84e85573218
diff --git a/lib/RenderScript/RSCompilerDriver.cpp b/lib/RenderScript/RSCompilerDriver.cpp
index a59a7f9..60a6d9d 100644
--- a/lib/RenderScript/RSCompilerDriver.cpp
+++ b/lib/RenderScript/RSCompilerDriver.cpp
@@ -228,7 +228,8 @@
//===--------------------------------------------------------------------===//
// Open the output file for write.
//===--------------------------------------------------------------------===//
- OutputFile *output_file = new (std::nothrow) OutputFile(pOutputPath);
+ OutputFile *output_file =
+ new (std::nothrow) OutputFile(pOutputPath, FileBase::kTruncate);
if ((output_file == NULL) || output_file->hasError()) {
ALOGE("Unable to open the %s for write! (%s)", pOutputPath,
diff --git a/lib/RenderScript/RSExecutable.cpp b/lib/RenderScript/RSExecutable.cpp
index bbb31db..e18167a 100644
--- a/lib/RenderScript/RSExecutable.cpp
+++ b/lib/RenderScript/RSExecutable.cpp
@@ -128,7 +128,7 @@
}
android::String8 info_path = RSInfo::GetPath(*mObjFile);
- OutputFile info_file(info_path.string());
+ OutputFile info_file(info_path.string(), FileBase::kTruncate);
if (info_file.hasError()) {
ALOGE("Failed to open the info file %s for write! (%s)", info_path.string(),
diff --git a/lib/Support/FileBase.cpp b/lib/Support/FileBase.cpp
index 2d50d08..1cc4283 100644
--- a/lib/Support/FileBase.cpp
+++ b/lib/Support/FileBase.cpp
@@ -40,6 +40,9 @@
mOpenFlags |= O_BINARY;
}
#endif
+ if (pFlags & kTruncate) {
+ mOpenFlags |= O_TRUNC;
+ }
// Open the file.
open();
diff --git a/lib/Support/OutputFile.cpp b/lib/Support/OutputFile.cpp
index 7d1c057..6d969d0 100644
--- a/lib/Support/OutputFile.cpp
+++ b/lib/Support/OutputFile.cpp
@@ -54,8 +54,9 @@
return NULL;
}
- // Create result OutputFile.
- result = new (std::nothrow) OutputFile(tmp_filename, pFlags);
+ // Create result OutputFile. Temporary file is always truncated.
+ result = new (std::nothrow) OutputFile(tmp_filename,
+ pFlags | FileBase::kTruncate);
if (result == NULL) {
ALOGE("Out of memory when creates OutputFile for %s!", tmp_filename);
// Fall through to the clean-up codes.