Repository navigation
XDG Changes #1060
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
XDG Changes #1060
Changes from all commits
54c64c9
29e97bf
237c659
4c1f9f9
c252719
caa4c3f
41c7f9e
42c0b9a
f46aa8d
a293707
140d452
0e10a51
4b0c916
d5f6295
539f869
a48c528
560bcaf
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 |
|---|---|---|
|
|
@@ -44,6 +44,15 @@ public static bool IsLinux | |
| } | ||
| } | ||
|
|
||
| //enum for selecting the xdgpaths | ||
| public enum XDG_Type | ||
| { | ||
| PROFILE, | ||
| MODULES, | ||
| CACHE, | ||
| DEFAULT | ||
| } | ||
|
|
||
| public static bool IsOSX | ||
| { | ||
| get | ||
|
|
@@ -96,8 +105,94 @@ public static bool IsCore | |
| "WSMan.format.ps1xml" | ||
| }; | ||
|
|
||
| // directory location of PowerShell for profile loading | ||
| public static string ProductNameForDirectory = ".powershell"; | ||
| // function for choosing directory location of PowerShell for profile loading | ||
| public static string SelectProductNameForDirectory (Platform.XDG_Type dirpath) | ||
|
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. Traditionally, we've named Linux functions in this file in the format "NonWindows...()". You may want to consider doing so, and add check to make sure this is not called from Windows code.
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. Take a look at LinuxPlatform.GetFolderPath() in this same file. Can you somehow integrate what you have with that?
Member
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. We need to get away from
Contributor
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. Okay, I'll change it back again.
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. Whether NonWindows is good or not, there's something to be said for consistency. GetFolderPath() is slightly different, but kind of related. Should default value for XDG_DATA_HOME be same as SpecialPath.LocalApplicationData?
Member
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. George Fleming (@palladia) this functionality is not splitting an existing function, where we would use Windows and NonWindows, it's adding additional functionality. The |
||
| { | ||
|
|
||
| //TODO: XDG_DATA_DIRS implementation as per GitHub issue #1060 | ||
|
|
||
|
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. Based on our conversation, changing the logic based on the input value will be efficient, easy to read and maintain for the future. |
||
| string xdgconfighome = System.Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); | ||
| string xdgdatahome = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); | ||
| string xdgcachehome = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME"); | ||
| string xdgConfigHomeDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".config", "powershell"); | ||
| string xdgModuleDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".local", "share", "powershell", "Modules"); | ||
| string xdgCacheDefault = Path.Combine (System.Environment.GetEnvironmentVariable("HOME"), ".cache", "powershell"); | ||
|
|
||
| switch (dirpath){ | ||
| case Platform.XDG_Type.PROFILE: | ||
| //the user has set XDG_CONFIG_HOME corrresponding to profile path | ||
| if (String.IsNullOrEmpty(xdgconfighome)) | ||
| { | ||
| //xdg values have not been set | ||
| return xdgConfigHomeDefault; | ||
| } | ||
|
|
||
| else | ||
| { | ||
| return Path.Combine(xdgconfighome, "powershell"); | ||
| } | ||
|
|
||
| case Platform.XDG_Type.MODULES: | ||
| //the user has set XDG_DATA_HOME corresponding to module path | ||
| if (String.IsNullOrEmpty(xdgdatahome)){ | ||
|
|
||
| //xdg values have not been set | ||
| if (!Directory.Exists(xdgModuleDefault)) //module folder not always guaranteed to exist | ||
| { | ||
| Directory.CreateDirectory(xdgModuleDefault); | ||
| } | ||
| return xdgModuleDefault; | ||
| } | ||
| else | ||
| { | ||
| return Path.Combine(xdgdatahome, "powershell", "Modules"); | ||
| } | ||
|
|
||
| case Platform.XDG_Type.CACHE: | ||
| //the user has set XDG_CACHE_HOME | ||
| if (String.IsNullOrEmpty(xdgcachehome)) | ||
| { | ||
| //xdg values have not been set | ||
| if (!Directory.Exists(xdgCacheDefault)) //module folder not always guaranteed to exist | ||
| { | ||
| Directory.CreateDirectory(xdgCacheDefault); | ||
| } | ||
|
|
||
| return xdgCacheDefault; | ||
| } | ||
|
|
||
| else | ||
| { | ||
| if (!Directory.Exists(Path.Combine(xdgcachehome, "powershell"))) | ||
| { | ||
| Directory.CreateDirectory(Path.Combine(xdgcachehome, "powershell")); | ||
| } | ||
|
|
||
| return Path.Combine(xdgcachehome, "powershell"); | ||
| } | ||
|
|
||
| case Platform.XDG_Type.DEFAULT: | ||
| //default for profile location | ||
| return xdgConfigHomeDefault; | ||
|
|
||
| default: | ||
| //xdgConfigHomeDefault needs to be created in the edge case that we do not have the folder or it was deleted | ||
| //This folder is the default in the event of all other failures for data storage | ||
| if (!Directory.Exists(xdgConfigHomeDefault)) | ||
| { | ||
| try { | ||
| Directory.CreateDirectory(xdgConfigHomeDefault); | ||
| } | ||
| catch{ | ||
|
|
||
| Console.Error.WriteLine("Failed to create default data directory: " + xdgConfigHomeDefault); | ||
| } | ||
| } | ||
|
|
||
| return xdgConfigHomeDefault; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // ComObjectType is null on CoreCLR for Linux since there is | ||
| // no COM support on Linux | ||
|
|
@@ -363,7 +458,7 @@ internal static string NonWindowsGetHostName() | |
| throw new InvalidOperationException("LinuxPlatform.NonWindowsHostName error: " + lastError); | ||
| } | ||
| return hostName; | ||
|
|
||
| } | ||
| else | ||
| { | ||
|
|
@@ -386,7 +481,7 @@ internal static uint NonWindowsGetThreadId() | |
| // TODO:PSL clean this up | ||
| return 0; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This exception is meant to be thrown if a code path is not supported due | ||
| /// to platform restrictions | ||
|
|
@@ -570,7 +665,7 @@ public static bool IsSymLink(FileSystemInfo fs) | |
| int ret = Native.IsSymLink(filePath); | ||
| switch(ret) | ||
| { | ||
| case 1: | ||
| case 1: | ||
| return true; | ||
| case 0: | ||
| return false; | ||
|
|
@@ -590,7 +685,7 @@ public static bool IsExecutable(string filePath) | |
| int ret = Native.IsExecutable(filePath); | ||
| switch(ret) | ||
| { | ||
| case 1: | ||
| case 1: | ||
| return true; | ||
| case 0: | ||
| return false; | ||
|
|
@@ -685,11 +780,11 @@ internal static class Native | |
| internal static extern int SetDate(SetDateInfoInternal info); | ||
|
|
||
| [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] | ||
| internal static extern int CreateSymLink([MarshalAs(UnmanagedType.LPStr)]string filePath, | ||
| internal static extern int CreateSymLink([MarshalAs(UnmanagedType.LPStr)]string filePath, | ||
| [MarshalAs(UnmanagedType.LPStr)]string target); | ||
|
|
||
| [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] | ||
| internal static extern int CreateHardLink([MarshalAs(UnmanagedType.LPStr)]string filePath, | ||
| internal static extern int CreateHardLink([MarshalAs(UnmanagedType.LPStr)]string filePath, | ||
| [MarshalAs(UnmanagedType.LPStr)]string target); | ||
|
|
||
| [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1015,8 +1015,10 @@ static AnalysisCacheData() | |
| { | ||
| cacheStoreLocation = | ||
| Environment.GetEnvironmentVariable("PSModuleAnalysisCachePath") ?? | ||
| Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), | ||
| @"Microsoft\Windows\PowerShell\ModuleAnalysisCache"); | ||
| (Platform.IsWindows | ||
| ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), | ||
| @"Microsoft\Windows\PowerShell\ModuleAnalysisCache") | ||
| : Path.Combine(Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE), "ModuleAnalysisCache")); | ||
| } | ||
|
Member
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. These changes cannot be tested automatically, but I've manually verified it worked. |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -606,7 +606,7 @@ internal static bool IsNetFrameworkVersionSupported(Version checkVersion, out bo | |
| /// Profile uses this to control profile loading. | ||
| /// </remarks> | ||
| internal static string ProductNameForDirectory = | ||
| Platform.IsWindows ? "WindowsPowerShell" : Platform.ProductNameForDirectory; | ||
| Platform.IsWindows ? "WindowsPowerShell" : Platform.SelectProductNameForDirectory(Platform.XDG_Type.PROFILE); | ||
|
Member
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. If this is receiving an XDGBDS path, that path is absolute, which is inconsistent with the Windows behavior. Something needs to be changed here.
Contributor
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. So I can change this, but Path.Combine has been why this has been okay. Path.Combine has some pretty flexible behaviors around this: I could see not wanting to rely on this behaivor, but it is pretty useful for our needs in this.
Member
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. Oh, that's awesome. I didn't know that. |
||
|
|
||
| /// <summary> | ||
| /// The name of the subdirectory that contains packages. | ||
|
|
||
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.
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.
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 don't get why history file goes in the "modules" directory.