Ecryptfs: Change not to remain temporary directory after encryption
[platform/core/security/ode.git] / server / engine / encryption / ecryptfs-engine.cpp
index ece06ad..9eaef01 100644 (file)
@@ -37,7 +37,7 @@
 #define MEDIA_EXCLUSION_LIST "temp_video/Camera/DCIM:mp3|mpga|m4a|mp4|wav|amr|awb|wma|ogg|oga|aac|mka|flac|3gp|3ga|mid|midi|xmf|rtttl|rtx|ota|smf|spm|imy|mpeg|m4v|3gp|3gpp|3g2|3gpp2|wmv|asf|mkv|webm|ts|avi|jpg|jpeg|gif|png|bmp|wbmp|divx|flv|ac3|mov|tiff|f4v|mpeg3|voice"
 
 #define CIPHER_MODE "aes"
-#define ENCRYPTION_CHECKER_NAME ".ecryptfs_encrypted"
+#define ENCRYPTION_TMP_DIR ".ecryptfs_encrypted"
 
 
 #define ECRYPTFS_VERSION_MAJOR 0x00
@@ -348,7 +348,11 @@ void EcryptfsEngine::encrypt(const data &key, unsigned int options)
 
        try {
                unsigned long long totalSize = getAvailableSpace(source), current;
-           runtime::File tempDir(destination + "/" ENCRYPTION_CHECKER_NAME);
+           runtime::File tempDir(destination + "/" ENCRYPTION_TMP_DIR);
+
+               if (tempDir.exists()) {
+                       tempDir.remove(true);
+               }
 
                tempDir.makeDirectory();
                if (!(options & OPTION_ONLY_NEW_FILE)) {
@@ -383,9 +387,11 @@ void EcryptfsEngine::decrypt(const data &key, unsigned int options)
 
        try {
                unsigned long long totalSize = getAvailableSpace(source), current;
-           runtime::File tempDir(source + "/" ENCRYPTION_CHECKER_NAME);
+           runtime::File tempDir(source + "/" ENCRYPTION_TMP_DIR);
                runtime::File tempMountpoint(tempDir.getPath() + "/mount");
 
+               tempDir.makeDirectory();
+
                tempMountpoint.makeDirectory();
                ecryptfsMount(source, tempMountpoint.getPath(), key, 0);