Commit graph

97 commits

Author SHA1 Message Date
Steve Lee 7459b54639 Set-Location should use path with wildcard characters if it exists instead of globbing (#5839)
When InitialSessionState initializes it tries to SetLocation to current working directory,
 but if the directory name contains PowerShell wildcard characters, it fails and reverts
 to $PSHOME.
 The change affects Set-Location in that if the path exists (even if containing wildcard characters), just use it. It is a breaking change.
2018-01-17 08:58:55 +04:00
Steve Lee 7407a9e300 Fix 'get-item -literalpath a*b' to return error if a*b doesn't actually exist (#5197) 2017-10-26 14:14:46 -07:00
Steve Lee 4bc52d2358 Use consistent '(c)' for copyright symbol (#5210)
- Remove the year about copyright
- Fix casing of `All rights reserved`
- Replace Unicode characters representing single quote with a single quote
2017-10-26 14:12:19 -07:00
James Truher [MSFT] be700729d6 Unify cmdlets with parameter 'Encoding' to be of type System.Text.Encoding (#5080)
This unifies file encoding across the inbox cmdlets to be UTF-8 without a BOM for all platforms. This is a breaking change as cmdlets on windows have a number of different encodings. This supports better interoperability with tradition Linux shells as we are using the same encoding.

Validate that files are created with UTF-8 encoding without BOM
Update tests to validate Encoding parameter to new type and create new tests for
parameter type validation.

[Breaking Change] The '-Encoding Byte' has been removed from the filesystem provider cmdlets. A new parameter '-AsByteStream' is now added to indicate that a byte stream is required as input, or output will be a stream of bytes.
2017-10-23 19:46:27 -07:00
Chunqing Chen 07d3b1806c Get-Content -Raw should not neglects to read the last character, if it is a LF (#5076) 2017-10-13 11:05:51 +04:00
Jason Shirk 22662c8c56 Remove dead code (#5066)
Code guarded by the following defines is ancient and has never been
used, so removing.
* RELATIONSHIP_SUPPORTED
* SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
* SUPPORTS_CMDLETPROVIDER_FILE
Also removed some unused platform dependent unsafe code.
2017-10-09 17:28:10 -07:00
Steve Lee 90165fc17c enable using filesystem from a UNC location (#4998)
* enable using filesystem from a UNC location

* [feature]
address PR feedback

* [feature]
removed changed in NavigationProviderBase and made change in FileSystemProvider where it should belong

* added variations of tests for set-location and push-location
no need to run [feature] anymore since it passed previously and the test case added is CI

* [feature]
move code to reproduce UNC path to GetParentPath()
2017-10-09 14:05:16 -07:00
Steve Lee 50607b9751 Enable support of folders and files with colon in name on Unix (#4959)
* [feature]
support folders and files with colon in name

* [feature]
only check separator in relation to colon if a colon is found

* [feature]
added comment to clarify algorithm

* added more tests
2017-10-06 11:27:15 -07:00
Steve Lee 7c9b188c13 Rename $IsOSX to $IsMacOS (#4757) 2017-09-07 10:34:40 -07:00
Steve Lee fb286e6cf8 Removed double spaces from .cs and .ps1 files (#4743) 2017-09-04 19:45:51 -07:00
Michael Klement 1de749fbaa Fix for Get-Content -Delimiter including the delimiter in the array elements returned (#3706) - functional changes 2017-09-01 13:01:43 -07:00
Steve Lee deb8c4485d Remove alternate file stream code from non-Windows (#4567)
* AlternateStreams support relies on pinvoke to win32 APIs which don't work on non-Windows and produces errors about not loading a DLL in the case of copy-item
* Address PR feedback, remove -Stream parameter for Unix added new -stream tests
* if/def out alternate stream syntax checks not applicable to Unix
2017-08-28 15:39:42 -07:00
Ilya 813e4a661a Fix unblock read only file (#4395)
Adds a new non-terminating error when a file is read-only
2017-08-14 08:49:38 -07:00
Dongbo Wang 384a9fe3fc Clean up ShellExecute code to use the .NET Core implementation (#4523)
* Clean up ShellExecuteHelper and enable ShellExecute in NativeCommandProcessor

* Minor fix

* [Feature] Fix NativeCommandProcessor to clean up in case an exception is thron

* [Feature] Update tests

* [Feature] Address comments

* address one more comment

* Address some more comments
2017-08-10 13:32:57 -07:00
Ilya 649ff285ee Clean up '#if CORE' in ProcessCodeMethods.cs and 'ClrFacade.GetSafeProcessHandle' (#4428) 2017-08-08 09:20:57 -07:00
Dongbo Wang 1462ac300b Clean up ClrFacade.cs - remove ClrFacade.PtrToStructure (#4379) 2017-07-29 22:34:31 -07:00
Dongbo Wang 2c43140276 Clean up ClrFacade.cs - remove ClrFacade.SizeOf<T>() (#4377) 2017-07-29 17:40:19 -07:00
Dongbo Wang 16f408c2f7 Clean up ClrFacade.cs - remove ClrFacade.StructureToPtr (#4380) 2017-07-29 16:44:44 -07:00
Ilya 184a9bc85e Clean up '#if CORE' - use SecurityZone from CoreFX (#4368)
Make `System.Management.Automation references` to package `System.Security.Permissions`, which brings back `SecurityZone` and `System.Security.Policy.Zone`.
2017-07-28 12:13:15 -07:00
Steve Lee 03d4e9120b Support Invoke-Item -Path <folder> (#4262)
On CoreFx, UseShellExecute for Process start is false by default to be cross platform compatible.
In the case of a folder, Process.Start() returns Access Denied as it's not an executable.
On Windows, we can use the ShellExecute path to have explorer open the folder. On Unix, we use `xdg-open` and `open` for Linux and macOS respectively.
2017-07-27 22:17:38 -07:00
bergmeister ffd39b2853 PSScriptAnalyzer fixes by category (#4261)
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'ForEach-Object' (alias is '%' or 'foreach')
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'Where-Object' (alias is '?' or 'where')
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'Select-Object' (alias is 'select')
- Fix PSScriptAnalyzer warnings of type PSPossibleIncorrectComparisonWithNull. Essentially, $null has to be on the left-hand side when using it for comparison.
- A Test in ParameterBinding.Tests.ps1 needed adapting as this test used to rely on the wrong null comparison
- Replace a subset of tests of kind '($object -eq $null) | Should Be $true' with '$object | Should Be $null'
2017-07-21 21:03:49 -07:00
jeffbi a9b8e98449 Remove unneeded test hooks and tests due to behavior change in .NET Core (#4200) 2017-07-08 15:18:48 -07:00
jeffbi 1688703caf Make Get-ChildItem follow symlinks on demand, with checks for link loops (#4020)
Add the dynamic parameter `-FollowSymlink` to `Get-ChildItem`.
Add a mechanism for tracking visited directories.
Add native code to get device/inode information on Unix/Windows.
Add warning when refusing to enter an already-visited directory.
2017-07-06 12:28:27 -07:00
jeffbi c29bd7d684 Make Get-ChildItem continue enumeration when encountering error on contained item (#3806)
Added try/catch within the enumeration loop to allow the enumeration to continue after encountering an error such as an item within the directory being deleted or renamed.

To assist in testing, two new internal test hooks have been added which cause Get-ChildItem to either delete or rename a specific file (file name hard-coded) when encountered during enumeration.
2017-05-25 17:24:47 -07:00
Dongbo Wang 99f9ef22d2 Fix "Invoke-Item" to accept a file path with spaces on Unix platforms (#3850)
Use the method NativeCommandParameterBinder.NeedQuotes, which is used by powershell native command processor, to check if quotes are needed. If yes, add quotes in the same way as our native command processor.
Also, make 'Invoke-Item' on Linux and OSX able to invoke an executable properly.
2017-05-24 13:30:54 -07:00
jeffbi ee1a897f91 Prevent Get-ChildItem from recursing into symlinks (#3780)
Brings the Get-ChildItem more in line with the Unix ls -r and the Windows DIR /S native commands. Like these commands, the cmdlet will display symbolic links to directories found during recursion but will not recurse into them.
Like the Unix ls command---and unlike the Windows DIR /S command--- the cmdlet will recurse into symlinks given on the command line.
2017-05-15 14:09:46 -07:00
jeffbi 938e13602b Change error message when using New-Item to create a symlink and the item exists (#3703) 2017-05-05 10:09:34 -07:00
jeffbi 3e416fb642 Change Get-ChildItem to list the content of a link to a directory on Unix. (#3697)
Brings Get-ChildItem in line with ls command on Unix and with the PowerShell behavior on Windows when the link is a directory symbolic link.
2017-05-04 18:00:13 -07:00
jeffbi 2a739afa9c Fix Rename-Item to allow Unix globbing patterns in paths (#2799) (#3661)
* Fix Rename-Item to allow Unix globbing patterns in -Literal paths (#2799)

In the process of normalizing a relative path, PowerShell checks to see
see if the path exists, which it does by invoking
    Directory.EnumerateFiles(directory, filename);

On Unix platforms, if the filename contains globbing patterns, such as [ab],
EnumerateFiles (and EnumerateDirectories) will perform the globbing. Using
globbing patterns, a file named 'file[txt].txt' is reported as not existing.

This fix changes the file-existence test on Unix to use a native function
instead of either of the Directory.EnumerateXXX functions.

* Fix for AppVeyor failure

* Changes per code review, and a couple of letter-casing changes.
2017-05-02 18:42:16 -07:00
jeffbi f1769fe7a8 Change behavior of Remove-Item on symbolic links (#621) (#3637)
When 'Remove-Item' is used to remove a symbolic link in Windows, only the link itself is removed. The '-Force' switch is no longer required.
If the directory pointed to by the link has child items, the cmdlet no longer prompts the user to remove the child items---those child items are not removed. The '-Recurse' switch, if given, is ignored.
This brings 'Remove-Item' more in line with the behavior of the 'rm' command on Unix.
2017-04-27 17:47:24 -07:00
Ilya 6db5c945b2 Remove unused and duplicated GetEncodingFromEnum (#3487) 2017-04-21 18:07:54 -07:00
jeffbi 8183732d99 Use more accurate test to check if source and destination paths are pointing the same file (#3441)
Rather than relying on case-insensitive string compares of source and destination paths, use operating system calls to determine whether two paths refer to the same file. This solves not only the case-insensitivity issue but also allows the cmdlet to operate properly if the destination is a hard or symbolic link to the source.
The Windows side is implemented in C#. The Unix side is implemented partially in native code.
2017-04-21 16:09:53 -07:00
Dongbo Wang 7a55bf98b2 Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 11:52:38 -07:00
jeffbi 06020f34e5 Fix New-Item to create correct symlink type (#2915) (#3509)
Now `New-Item` can create a file symlink to a file target or to a non-existent target. It can also create a directory symlink to a directory target on Windows.
2017-04-14 14:23:14 -07:00
Ilya 0883438e55 Fix Default/OEM encoding behavior PowerShell Core (#3467)
Based on the conclusion in discussion #3248, this PR fix "OEM" and "Default" encoding in powershell.
1. OEM -- We need an internal fix because .Net Core has no "OEM" encoding.
The fix gives the following PowerShell Core behavior on "OEM" encoding:
   - on Windows - as Windows PowerShell based on GetOEMCP() and legacy encodings (System.Text.Encoding.CodePages)
   - on Unix - the same as default encoding in PowerShell Core

2. Default -- We need internal fix because CoreFX `Encoding.default` for all platforms is UTF8.
Until we complete the `Encoding RFC` we should restore behavior as in Windows PowerShell.
The fix gives the following PowerShell Core behavior on "Default" encoding:
   - on Windows - as Windows PowerShell based on GetACP() and legacy encodings (System.Text.Encoding.CodePages)
   - on Unix - UTF-8 without BOM (We are expecting that the same will be [in CoreFX](https://github.com/dotnet/coreclr/issues/10643))
2017-04-05 18:22:18 -07:00
Dongbo Wang 7f83c48ca5 Add support to ShellExecute in powershell core when it's running on Windows full SKUs (#3281)
* Add ShellExecute support to PowerShell core on windows full desktop
* Add tests for Start-Process and update existing related tests
2017-03-14 11:11:41 -07:00
Jason Shirk 02b5f357a2 Remove trailing whitespace (#3001) 2017-01-16 13:31:14 -08:00
David Christian 9c9b56d22f Updated Split-Path to work with UNC Roots (#2788) 2016-12-04 15:00:32 -08:00
Jason Shirk (POWERSHELL) 386b4f37f4 Remove CheckForSevereException and private FailFast
Our private implementation of FailFast was likely introduced
when each individual application needed it's own code to
get Watson reports. The CLR takes care of this for us now,
so we don't need our implementation.

Our method CheckForSevereException was also introduced in
the early days of the CLR - the exceptions it was checking
for aren't actually raised the CLR anymore, they just FailFast.
I removed them as there is a tiny bit of overhead (in code size)
and also in the generated code, e.g. dynamic sites called the method.
2016-12-01 13:46:56 -08:00
Sergei Vorobev 3363b248a0 Fix code errors found by PVS-Studio (#2695)
* Fix errors found by PSV-studio analyzer

http://www.viva64.com/en/b/0447/

* Remove old redundent comment

errorAsts is passed by ref
2016-11-17 11:20:04 -08:00
Matt Wrock e1db642c7f Ensure *nix platforms add an initial / rooted drive (#2679) 2016-11-15 10:27:12 -08:00
Charu Bassi 85825e2b0b Fix Resolve-Path -LiteralPath for drive paths (#2572)
Resolving #2570.
Ignore drive paths in the check. If the input is a drive path,
then "\" is passed as the path to GetDriveQualifiedPath with drive info.
Since, the path here starts with "\", treatAsRelative is set to false
which prevents further formatting of this path.
The check is only valid for PSDrives with root path equals to UNC paths or the paths
in unix.
2016-11-01 18:01:52 -07:00
Charu Bassi ee2feaa827 Fix set-content failure for creating file in psdrive. (#2392)
Resolving #2206

Set-Content fails to create a file for PSDrive path, if the path root
begins with defaultPathSeperatorString (ex: UNC path and paths in Single
rooted filesystems like Unix)
2016-10-28 14:31:02 -07:00
Andrew Schwartzmeyer 2a6b84ed1b Clean up IsHardLink 2016-10-14 15:42:59 -07:00
Andrew Schwartzmeyer b4b2278571 Clean up CreateHardLink 2016-10-14 15:42:58 -07:00
Andrew Schwartzmeyer 0ce5575f57 Clean up CreateSymLink 2016-10-14 15:42:58 -07:00
Andrew Schwartzmeyer 82867a5c12 Clean up FollowSymLink 2016-10-14 15:30:19 -07:00
Andrew Schwartzmeyer 196a37b118 Add native errno to ErrorCategory mapper 2016-10-14 15:30:19 -07:00
Andrew Schwartzmeyer e1aeeaa9c2 Switch to Win32Exception(GetLastWin32Error)
This is verified to work "correctly" on Linux in that it gets the
`perror` for the last set value of errno in native code.

No extra mapping or handling needs to be done on our part.

Keeping the strerror_r implementation in the history for the valuable
implementation of config.h.in in the library.
2016-10-14 15:30:19 -07:00
Dongbo Wang f02b6ef97a Exclude 'Registry' and 'Certificate' providers from UNIX PS since they don't work on UNIX platform.
With this change, 'Registry' and 'Certificate' providers won't be compiled for UNIX PS.
2016-10-14 10:02:44 -07:00