tool: renewed sdcard preparation logic
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 11 Jun 2015 06:13:28 +0000 (15:13 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 12 Jun 2015 08:28:12 +0000 (17:28 +0900)
We will copy sdcard images if new images are provided.

Change-Id: I1f9c2bb512334ee86b49975f39bf278df3b79cca

src/org/tizen/emulator/manager/tool/CheckEmulatorDir.java

index 66abc78..22bba76 100644 (file)
@@ -36,6 +36,7 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.logging.Level;
 
@@ -101,7 +102,7 @@ public class CheckEmulatorDir {
 
        public static void CheckSDCardDir() {
                File dir = new File(FilePathResources.getSDCardPath());
-               
+
                if (!dir.exists()) {
                        dir.mkdir();
                }
@@ -110,13 +111,28 @@ public class CheckEmulatorDir {
                        Path source = Paths.get(FilePathResources.getBaseSdcardPath(), s);
                        Path target = Paths.get(FilePathResources.getSDCardPath(), s);
 
-                       if (!target.toFile().exists()) {
-                               try {
-                                       Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
-                               } catch (IOException e2) {
-                                       EMLogger.getLogger().log(Level.WARNING, "Failed to create SD card image!"
-                                                       + StringResources.NEW_LINE + e2.getMessage());
+                       if (!Files.exists(source)) {
+                               EMLogger.getLogger().log(Level.SEVERE, "Base SDCARD image is not exist !!!");
+                               break;
+                       }
+
+                       try {
+                               if (Files.exists(target)) {
+                                       BasicFileAttributes sourceAttr = Files.readAttributes(source, BasicFileAttributes.class);
+                                       BasicFileAttributes targetAttr = Files.readAttributes(target, BasicFileAttributes.class);
+
+                                       // copy sdcard images if only new sdcard images are provided.
+                                       if (sourceAttr.lastModifiedTime().compareTo(targetAttr.lastModifiedTime()) <= 0) {
+                                               // FIXME: if newer images are exist,
+                                               // we should warn to user before replace legacy images.
+                                               continue;
+                                       }
                                }
+
+                               Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
+                       } catch (IOException e) {
+                               EMLogger.getLogger().log(Level.SEVERE, "Failed to create SDCARD image !!!"
+                                               + StringResources.NEW_LINE + e.getMessage());
                        }
                }
        }