src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBundler.java
branchJDK-8200758-branch
changeset 58434 b00cbf427368
parent 58417 67ffaf3a2b75
child 58435 788704ff2559
equal deleted inserted replaced
58419:18e27ee2276b 58434:b00cbf427368
    88 
    88 
    89         // run basic validation to ensure requirements are met
    89         // run basic validation to ensure requirements are met
    90         // we are not interested in return code, only possible exception
    90         // we are not interested in return code, only possible exception
    91         APP_BUNDLER.fetchFrom(params).validate(params);
    91         APP_BUNDLER.fetchFrom(params).validate(params);
    92 
    92 
       
    93         validateInstallDir(LINUX_INSTALL_DIR.fetchFrom(params));
       
    94 
    93         validateFileAssociations(FILE_ASSOCIATIONS.fetchFrom(params));
    95         validateFileAssociations(FILE_ASSOCIATIONS.fetchFrom(params));
    94 
    96 
    95         // If package name has some restrictions, the string converter will
    97         // If package name has some restrictions, the string converter will
    96         // throw an exception if invalid
    98         // throw an exception if invalid
    97         packageName.getStringConverter().apply(packageName.fetchFrom(params),
    99         packageName.getStringConverter().apply(packageName.fetchFrom(params),
   301             return ApplicationLayout.javaRuntime();
   303             return ApplicationLayout.javaRuntime();
   302         }
   304         }
   303         return ApplicationLayout.linuxAppImage();
   305         return ApplicationLayout.linuxAppImage();
   304     }
   306     }
   305 
   307 
       
   308     private static void validateInstallDir(String installDir) throws
       
   309             ConfigException {
       
   310         if (installDir.startsWith("/usr/") || installDir.equals("/usr")) {
       
   311             throw new ConfigException(MessageFormat.format(I18N.getString(
       
   312                     "error.unsupported-install-dir"), installDir), null);
       
   313         }
       
   314 
       
   315         if (installDir.isEmpty()) {
       
   316             throw new ConfigException(MessageFormat.format(I18N.getString(
       
   317                     "error.invalid-install-dir"), "/"), null);
       
   318         }
       
   319 
       
   320         boolean valid = false;
       
   321         try {
       
   322             final Path installDirPath = Path.of(installDir);
       
   323             valid = installDirPath.isAbsolute();
       
   324             if (valid && !installDirPath.normalize().toString().equals(
       
   325                     installDirPath.toString())) {
       
   326                 // Don't allow '/opt/foo/..' or /opt/.
       
   327                 valid = false;
       
   328             }
       
   329         } catch (InvalidPathException ex) {
       
   330         }
       
   331 
       
   332         if (!valid) {
       
   333             throw new ConfigException(MessageFormat.format(I18N.getString(
       
   334                     "error.invalid-install-dir"), installDir), null);
       
   335         }
       
   336     }
       
   337 
   306     private static void validateFileAssociations(
   338     private static void validateFileAssociations(
   307             List<Map<String, ? super Object>> associations) throws
   339             List<Map<String, ? super Object>> associations) throws
   308             ConfigException {
   340             ConfigException {
   309         // only one mime type per association, at least one file extention
   341         // only one mime type per association, at least one file extention
   310         int assocIdx = 0;
   342         int assocIdx = 0;