Esempio n. 1
0
 private static boolean canWrite(URL location) {
   if (location != null && "file".equals(location.getProtocol())) { // $NON-NLS-1$
     File locationDir = new File(location.getFile());
     if (!locationDir.exists()) locationDir.mkdirs();
     if (locationDir.exists() && AdaptorUtil.canWrite(locationDir)) return true;
   }
   return false;
 }
Esempio n. 2
0
  private static String computeDefaultConfigurationLocation() {
    // 1) We store the config state relative to the 'eclipse' directory if possible
    // 2) If this directory is read-only
    //    we store the state in <user.home>/.eclipse/<application-id>_<version> where <user.home>
    //    is unique for each local user, and <application-id> is the one
    //    defined in .eclipseproduct marker file. If .eclipseproduct does not
    //    exist, use "eclipse" as the application-id.

    URL installURL = computeInstallConfigurationLocation();
    if (installURL != null && "file".equals(installURL.getProtocol())) { // $NON-NLS-1$
      File installDir = new File(installURL.getFile());
      File defaultConfigDir = new File(installDir, CONFIG_DIR);
      if (!defaultConfigDir.exists()) defaultConfigDir.mkdirs();
      if (defaultConfigDir.exists() && AdaptorUtil.canWrite(defaultConfigDir))
        return defaultConfigDir.getAbsolutePath();
    }
    // We can't write in the eclipse install dir so try for some place in the user's home dir
    return computeDefaultUserAreaLocation(CONFIG_DIR);
  }
  /** This file is a copy of {@link ZipBundleFile#getFile(String, boolean)} with modifications. */
  @Override
  public File getFile(String path, boolean nativeCode) {
    File originalFile = delegate.getFile(path, nativeCode);

    if (originalFile == null) {
      return null;
    }
    if (!hasTransforms(path)) {
      return originalFile;
    }
    try {
      File nested = getExtractFile(path);
      if (nested != null) {
        if (nested.exists()) {
          /* the entry is already cached */
          if (Debug.DEBUG_GENERAL) {
            Debug.println("File already present: " + nested.getPath()); // $NON-NLS-1$
          }
          if (nested.isDirectory()) {
            // must ensure the complete directory is extracted (bug
            // 182585)
            extractDirectory(path);
          }
        } else {
          if (originalFile.isDirectory()) {
            if (!nested.mkdirs()) {
              if (Debug.DEBUG_GENERAL) {
                Debug.println("Unable to create directory: " + nested.getPath()); // $NON-NLS-1$
              }
              throw new IOException(
                  NLS.bind(
                      AdaptorMsg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, nested.getAbsolutePath()));
            }
            extractDirectory(path);
          } else {
            InputStream in = getEntry(path).getInputStream();
            if (in == null) {
              return null;
            }
            // if (in instanceof )
            /* the entry has not been cached */
            if (Debug.DEBUG_GENERAL) {
              Debug.println("Creating file: " + nested.getPath()); // $NON-NLS-1$
            }
            /* create the necessary directories */
            File dir = new File(nested.getParent());
            if (!dir.exists() && !dir.mkdirs()) {
              if (Debug.DEBUG_GENERAL) {
                Debug.println("Unable to create directory: " + dir.getPath()); // $NON-NLS-1$
              }
              throw new IOException(
                  NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, dir.getAbsolutePath()));
            }
            /* copy the entry to the cache */
            AdaptorUtil.readFile(in, nested);
            if (nativeCode) {
              setPermissions(nested);
            }
          }
        }

        return nested;
      }
    } catch (IOException e) {
      if (Debug.DEBUG_GENERAL) {
        Debug.printStackTrace(e);
      }
    }
    return null;
  }