Change backend._OSSearch return values
authorIustin Pop <iustin@google.com>
Thu, 10 Apr 2008 13:36:21 +0000 (13:36 +0000)
committerIustin Pop <iustin@google.com>
Thu, 10 Apr 2008 13:36:21 +0000 (13:36 +0000)
Currently, the function backend._OSSearch() returns the (first) base dir
in which this OS can be found. Thereafter the full actual path to the OS
dir is built in the backend.OSFromDisk() function.

This patch changes this so that _OSSearch() always returns the full path
to the OS directory, and OSFromDisk uses that as returned (it will only
build it if it gets a base dir in the first place).

This patch is needed before we can abstract the _OSSearch into a generic
'look for file object' functionality that can be used for allocator
plugins search too.

Reviewed-by: ultrotter

lib/backend.py

index ab03e76..c593006 100644 (file)
@@ -988,7 +988,7 @@ def _OSSearch(name, search_path=None):
   for dir_name in search_path:
     t_os_dir = os.path.sep.join([dir_name, name])
     if os.path.isdir(t_os_dir):
-      return dir_name
+      return t_os_dir
 
   return None
 
@@ -1082,12 +1082,12 @@ def OSFromDisk(name, base_dir=None):
   """
 
   if base_dir is None:
-    base_dir = _OSSearch(name)
-
-  if base_dir is None:
-    raise errors.InvalidOS(name, None, "OS dir not found in search path")
+    os_dir = _OSSearch(name)
+    if os_dir is None:
+      raise errors.InvalidOS(name, None, "OS dir not found in search path")
+  else:
+    os_dir = os.path.sep.join([base_dir, name])
 
-  os_dir = os.path.sep.join([base_dir, name])
   api_version = _OSOndiskVersion(name, os_dir)
 
   if api_version != constants.OS_API_VERSION: