Introduce InputFile/OutputFile and FileMutex.

FileHandle is replaced with InputFile/OutputFile and FileMutex.

Use InputFile when you want to open a file in read-only.
USe OutputFile when you open a file for writing.
Both of them provide a reliable way to access the files and perform
the I/O operations.

Given a name "foo", FileMutex creates a file named "foo.lock" and
tries to acquire an advisory lock (flock) on this file.

FileHandle, which uses the file it's openning for locking, may corrupt
the file contents when two or more processes are trying to gain the
lock for reading/writing. For example:

Process #2 creates foo
Process #1 opens foo
Process #2 opens foo
Process #2 locks foo (exclusively) (success)
Process #1 locks foo (failed, retry #1)
Process #2 starts writing foo
Process #1 opens and truncates foo (note there’s O_TRUNC in the flag)
Process #2 writes foo continually (foo is corrupted from now on ...)
Process #1 locks foo (failed, retry #2)
...
Process #1 locks foo (reach the max retries and return)
Process #2 gets done on writing foo (foo is corrupted ...)
Process #2 unlocks and closes foo (foo is corrupted)
diff --git a/lib/ExecutionEngine/Sha1Helper.cpp b/lib/ExecutionEngine/Sha1Helper.cpp
index 0acd6b8..07a995f 100644
--- a/lib/ExecutionEngine/Sha1Helper.cpp
+++ b/lib/ExecutionEngine/Sha1Helper.cpp
@@ -19,7 +19,7 @@
 #include "Config.h"
 
 #include "DebugHelper.h"
-#include "FileHandle.h"
+#include "InputFile.h"
 
 #include <string.h>
 
@@ -50,10 +50,11 @@
 void calcFileSHA1(unsigned char *result, char const *filename) {
   android::StopWatch calcFileSHA1Timer("calcFileSHA1 time");
 
-  FileHandle file;
+  InputFile file(filename);
 
-  if (file.open(filename, OpenMode::Read) < 0) {
-    ALOGE("Unable to calculate the sha1 checksum of %s\n", filename);
+  if (file.hasError()) {
+    ALOGE("Unable to open the file %s before SHA-1 checksum "
+          "calculation! (%s)", filename, file.getErrorMessage().c_str());
     memset(result, '\0', 20);
     return;
   }
@@ -83,9 +84,10 @@
 }
 
 void readSHA1(unsigned char *result, int result_size, char const *filename) {
-  FileHandle file;
-  if (file.open(filename, OpenMode::Read) < 0) {
-    ALOGE("Unable to read binary sha1 file %s\n", filename);
+  InputFile file(filename);
+  if (file.hasError()) {
+    ALOGE("Unable to open the binary sha1 file %s! (%s)", filename,
+          file.getErrorMessage().c_str());
     memset(result, '\0', result_size);
     return;
   }