summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kraft <george.kraft@calxeda.com>2012-09-14 14:24:23 -0500
committerGeorge Kraft <george.kraft@calxeda.com>2012-09-14 14:24:23 -0500
commit67b26c2d8d40cd991ddbfe06a5db63dbacf76284 (patch)
tree5b582b9cf4baf40726091f5318d52bd6fc4cbdea
parentc3ef914d3afab7d983c8ccfb9d4c1b8dbeca9c71 (diff)
downloadcxmanage-67b26c2d8d40cd991ddbfe06a5db63dbacf76284.tar.gz
CXMAN-14: Use "file" to verify image types
We used to do this anyway, but I removed it for windows support. Of course, Cygwin has the "file" tool anyway so we should be ok.
-rw-r--r--cxmanage/image.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/cxmanage/image.py b/cxmanage/image.py
index 11ffdd4..7819be0 100644
--- a/cxmanage/image.py
+++ b/cxmanage/image.py
@@ -32,6 +32,7 @@
""" Image objects used by the cxmanage controller """
import os
+import subprocess
import tempfile
from cxmanage import CxmanageError
@@ -107,13 +108,24 @@ class Image:
def verify(self):
""" Return true if the image is valid, false otherwise """
+ try:
+ file_type = subprocess.check_output(["file", self.filename]
+ ).split()[1]
+ if self.type == "SOC_ELF":
+ if file_type != "ELF":
+ return False
+ elif file_type != "data":
+ return False
+ except OSError:
+ # "file" tool wasn't found, just continue without it
+ pass
if self.type in ["CDB", "BOOT_LOG"]:
# Look for "CDBH"
contents = open(self.filename).read()
if self.simg:
contents = get_simg_contents(contents)
-
- return contents[:4] == "CDBH"
+ if contents[:4] != "CDBH":
+ return False
return True