Revision b2b8bcce lib/backend.py

b/lib/backend.py
2050 2050
  base_file_storage_dir = cfg.GetFileStorageDir()
2051 2051
  if (not os.path.commonprefix([file_storage_dir, base_file_storage_dir]) ==
2052 2052
      base_file_storage_dir):
2053
    logging.error("file storage directory '%s' is not under base file"
2054
                  " storage directory '%s'",
2055
                  file_storage_dir, base_file_storage_dir)
2056
    return None
2053
    _Fail("File storage directory '%s' is not under base file"
2054
          " storage directory '%s'", file_storage_dir, base_file_storage_dir)
2057 2055
  return file_storage_dir
2058 2056

  
2059 2057

  
......
2069 2067

  
2070 2068
  """
2071 2069
  file_storage_dir = _TransformFileStorageDir(file_storage_dir)
2072
  result = True,
2073
  if not file_storage_dir:
2074
    result = False,
2070
  if os.path.exists(file_storage_dir):
2071
    if not os.path.isdir(file_storage_dir):
2072
      _Fail("Specified storage dir '%s' is not a directory",
2073
            file_storage_dir)
2075 2074
  else:
2076
    if os.path.exists(file_storage_dir):
2077
      if not os.path.isdir(file_storage_dir):
2078
        logging.error("'%s' is not a directory", file_storage_dir)
2079
        result = False,
2080
    else:
2081
      try:
2082
        os.makedirs(file_storage_dir, 0750)
2083
      except OSError, err:
2084
        logging.error("Cannot create file storage directory '%s': %s",
2085
                      file_storage_dir, err)
2086
        result = False,
2087
  return result
2075
    try:
2076
      os.makedirs(file_storage_dir, 0750)
2077
    except OSError, err:
2078
      _Fail("Cannot create file storage directory '%s': %s",
2079
            file_storage_dir, err, exc=True)
2080
  return True, None
2088 2081

  
2089 2082

  
2090 2083
def RemoveFileStorageDir(file_storage_dir):
......
2100 2093

  
2101 2094
  """
2102 2095
  file_storage_dir = _TransformFileStorageDir(file_storage_dir)
2103
  result = True,
2104
  if not file_storage_dir:
2105
    result = False,
2106
  else:
2107
    if os.path.exists(file_storage_dir):
2108
      if not os.path.isdir(file_storage_dir):
2109
        logging.error("'%s' is not a directory", file_storage_dir)
2110
        result = False,
2111
      # deletes dir only if empty, otherwise we want to return False
2112
      try:
2113
        os.rmdir(file_storage_dir)
2114
      except OSError, err:
2115
        logging.exception("Cannot remove file storage directory '%s'",
2116
                          file_storage_dir)
2117
        result = False,
2118
  return result
2096
  if os.path.exists(file_storage_dir):
2097
    if not os.path.isdir(file_storage_dir):
2098
      _Fail("Specified Storage directory '%s' is not a directory",
2099
            file_storage_dir)
2100
    # deletes dir only if empty, otherwise we want to return False
2101
    try:
2102
      os.rmdir(file_storage_dir)
2103
    except OSError, err:
2104
      _Fail("Cannot remove file storage directory '%s': %s",
2105
            file_storage_dir, err)
2106

  
2107
  return True, None
2119 2108

  
2120 2109

  
2121 2110
def RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir):
......
2132 2121
  """
2133 2122
  old_file_storage_dir = _TransformFileStorageDir(old_file_storage_dir)
2134 2123
  new_file_storage_dir = _TransformFileStorageDir(new_file_storage_dir)
2135
  result = True,
2136
  if not old_file_storage_dir or not new_file_storage_dir:
2137
    result = False,
2138
  else:
2139
    if not os.path.exists(new_file_storage_dir):
2140
      if os.path.isdir(old_file_storage_dir):
2141
        try:
2142
          os.rename(old_file_storage_dir, new_file_storage_dir)
2143
        except OSError, err:
2144
          logging.exception("Cannot rename '%s' to '%s'",
2145
                            old_file_storage_dir, new_file_storage_dir)
2146
          result =  False,
2147
      else:
2148
        logging.error("'%s' is not a directory", old_file_storage_dir)
2149
        result = False,
2124
  if not os.path.exists(new_file_storage_dir):
2125
    if os.path.isdir(old_file_storage_dir):
2126
      try:
2127
        os.rename(old_file_storage_dir, new_file_storage_dir)
2128
      except OSError, err:
2129
        _Fail("Cannot rename '%s' to '%s': %s",
2130
              old_file_storage_dir, new_file_storage_dir, err)
2150 2131
    else:
2151
      if os.path.exists(old_file_storage_dir):
2152
        logging.error("Cannot rename '%s' to '%s'. Both locations exist.",
2153
                      old_file_storage_dir, new_file_storage_dir)
2154
        result = False,
2155
  return result
2132
      _Fail("Specified storage dir '%s' is not a directory",
2133
            old_file_storage_dir)
2134
  else:
2135
    if os.path.exists(old_file_storage_dir):
2136
      _Fail("Cannot rename '%s' to '%s': both locations exist",
2137
            old_file_storage_dir, new_file_storage_dir)
2138
  return True, None
2156 2139

  
2157 2140

  
2158 2141
def _IsJobQueueFile(file_name):

Also available in: Unified diff