-
Notifications
You must be signed in to change notification settings - Fork 397
Use XDG base directories and Known Folders on Windows #1809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import java.net.URI | |
| import java.nio.file.Files | ||
| import java.nio.file.Path | ||
| import java.util.regex.Pattern | ||
| import kotlin.io.path.absolutePathString | ||
| import kotlin.io.path.isRegularFile | ||
| import org.pkl.core.* | ||
| import org.pkl.core.evaluatorSettings.PklEvaluatorSettings | ||
|
|
@@ -33,6 +34,7 @@ import org.pkl.core.project.Project | |
| import org.pkl.core.resource.ResourceReader | ||
| import org.pkl.core.resource.ResourceReaders | ||
| import org.pkl.core.settings.PklSettings | ||
| import org.pkl.core.util.DebugLogger | ||
| import org.pkl.core.util.IoUtils | ||
|
|
||
| /** Building block for CLI commands. Configured programmatically to allow for embedding. */ | ||
|
|
@@ -69,7 +71,7 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) { | |
| if (cliOptions.normalizedSettingsModule != null) { | ||
| PklSettings.load(ModuleSource.uri(cliOptions.normalizedSettingsModule)) | ||
| } else { | ||
| PklSettings.loadFromPklHomeDir() | ||
| PklSettings.loadFromSystem() | ||
| } | ||
| } catch (e: PklException) { | ||
| // do not use `errorRenderer` because it depends on `settings` | ||
|
|
@@ -146,7 +148,7 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) { | |
| ?: evaluatorSettings?.let { settings -> | ||
| if (settings.noCache == true) null else settings.moduleCacheDir | ||
| } | ||
| ?: IoUtils.getDefaultModuleCacheDir() | ||
| ?: IoUtils.getSystemModuleCacheDir() | ||
| } | ||
|
|
||
| protected val modulePath: List<Path> by lazy { | ||
|
|
@@ -215,7 +217,7 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) { | |
| } | ||
|
|
||
| private fun HttpClient.Builder.addDefaultCliCertificates() { | ||
| val caCertsDir = IoUtils.getPklHomeDir().resolve("cacerts") | ||
| val caCertsDir = IoUtils.getSystemCaCertsDir() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change to cacerts means that the certs can now be silently diverted via an env var. I'm not sure this is a good call security-wise.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this any different from diverting the path of the |
||
| var certsAdded = false | ||
| if (Files.isDirectory(caCertsDir)) { | ||
| Files.list(caCertsDir) | ||
|
|
@@ -225,7 +227,10 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) { | |
| addCertificates(cert) | ||
| } | ||
| } | ||
| if (!certsAdded) { | ||
| if (certsAdded) { | ||
| DebugLogger.log("Loading CA certificates from ${caCertsDir.normalize().absolutePathString()}") | ||
| } else { | ||
| DebugLogger.log("Using built-in CA certificates") | ||
| val defaultCerts = | ||
| this@CliCommand.javaClass.classLoader.getResourceAsStream( | ||
| "org/pkl/commons/cli/PklCARoots.pem" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright © 2026 Apple Inc. and the Pkl project authors. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.pkl.core.util; | ||
|
|
||
| final class BaseDirectories { | ||
| public static final BaseDirectory config = | ||
| new BaseDirectory( | ||
| "XDG_CONFIG_HOME", | ||
| "XDG_CONFIG_DIRS", | ||
| "APPDATA", | ||
| null, | ||
| ".config", | ||
| new String[] {"/etc/xdg"}); | ||
|
|
||
| public static final BaseDirectory cache = | ||
| new BaseDirectory("XDG_CACHE_HOME", null, "LOCALAPPDATA", "Cache", ".cache", null); | ||
|
|
||
| public static final BaseDirectory state = | ||
| new BaseDirectory("XDG_STATE_HOME", null, "LOCALAPPDATA", null, ".local/state", null); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it might make sense to have a one-time "new cache not found, but old cache is present" copy/link migration to make some attempt to reuse existing cache dirs. Cost to re-build is low, but still non-zero, especially on slow connections.