diff --git a/CHANGELOG.md b/CHANGELOG.md index e68db6faa..fc81b9b6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,7 +47,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed `Set-PnPTerm` cmdlet throwing object reference error when only the term Id is specified. [#3341](https://github.com/pnp/powershell/pull/3341) - Fixed `New-PnPTeamsTeam` cmdlet throwing an error when specifying members [#3351](https://github.com/pnp/powershell/pull/3351) - Fixed `New-PnPTeamsTeam` cmdlet not working well with a managed identity [#3351](https://github.com/pnp/powershell/pull/3351) - +- Fixed `Copy-PnPFile`, `Copy-PnPFolder` and `Move-PnPFile` to better handle copying or moving operations to OneDrive or Multi-geo environments. [#3245](https://github.com/pnp/powershell/pull/3245) + ### Changed - Improved `Set-PnPListItem` cmdlet handling of Purview labels. [#3340](https://github.com/pnp/powershell/pull/3340) diff --git a/src/Commands/Files/CopyFile.cs b/src/Commands/Files/CopyFile.cs index 72cc92ef9..12dc64ca6 100644 --- a/src/Commands/Files/CopyFile.cs +++ b/src/Commands/Files/CopyFile.cs @@ -42,8 +42,8 @@ protected override void ExecuteCmdlet() if (!SourceUrl.StartsWith("/")) { SourceUrl = UrlUtility.Combine(webServerRelativeUrl, SourceUrl); - } - if (!TargetUrl.StartsWith("/")) + } + if (!TargetUrl.StartsWith("https://") && !TargetUrl.StartsWith("/")) { TargetUrl = UrlUtility.Combine(webServerRelativeUrl, TargetUrl); } @@ -58,7 +58,16 @@ protected override void ExecuteCmdlet() Uri sourceUri = new Uri(currentContextUri, EncodePath(sourceFolder)); Uri sourceWebUri = Microsoft.SharePoint.Client.Web.WebUrlFromFolderUrlDirect(ClientContext, sourceUri); Uri targetUri = new Uri(currentContextUri, EncodePath(targetFolder)); - Uri targetWebUri = Microsoft.SharePoint.Client.Web.WebUrlFromFolderUrlDirect(ClientContext, targetUri); + Uri targetWebUri; + if (TargetUrl.StartsWith("https://")) + { + targetUri = new Uri(TargetUrl); + targetWebUri = targetUri; + } + else + { + targetWebUri = Microsoft.SharePoint.Client.Web.WebUrlFromFolderUrlDirect(ClientContext, targetUri); + } if (Force || ShouldContinue(string.Format(Resources.CopyFile0To1, SourceUrl, TargetUrl), Resources.Confirm)) { @@ -104,7 +113,7 @@ private void Copy(Uri currentContextUri, Uri source, Uri destination, string sou { sourceUrl = $"{source.Scheme}://{source.Host}/{sourceUrl.TrimStart('/')}"; } - if (!targetUrl.StartsWith(destination.ToString())) + if (!targetUrl.StartsWith("https://") && !targetUrl.StartsWith(destination.ToString())) { targetUrl = $"{destination.Scheme}://{destination.Host}/{targetUrl.TrimStart('/')}"; } diff --git a/src/Commands/Files/MoveFile.cs b/src/Commands/Files/MoveFile.cs index fc3b43d47..c30ae836d 100644 --- a/src/Commands/Files/MoveFile.cs +++ b/src/Commands/Files/MoveFile.cs @@ -50,7 +50,7 @@ protected override void ExecuteCmdlet() { SourceUrl = UrlUtility.Combine(webServerRelativeUrl, SourceUrl); } - if (!TargetUrl.StartsWith("/")) + if (!TargetUrl.StartsWith("https://") && !TargetUrl.StartsWith("/")) { TargetUrl = UrlUtility.Combine(webServerRelativeUrl, TargetUrl); } @@ -66,7 +66,16 @@ protected override void ExecuteCmdlet() Uri sourceUri = new Uri(currentContextUri, EncodePath(sourceFolder)); Uri sourceWebUri = Web.WebUrlFromFolderUrlDirect(ClientContext, sourceUri); Uri targetUri = new Uri(currentContextUri, EncodePath(targetFolder)); - Uri targetWebUri = Web.WebUrlFromFolderUrlDirect(ClientContext, targetUri); + Uri targetWebUri; + if (TargetUrl.StartsWith("https://")) + { + targetUri = new Uri(TargetUrl); + targetWebUri = targetUri; + } + else + { + targetWebUri = Microsoft.SharePoint.Client.Web.WebUrlFromFolderUrlDirect(ClientContext, targetUri); + } if (Force || ShouldContinue(string.Format(Resources.MoveFile0To1, SourceUrl, TargetUrl), Resources.Confirm)) { @@ -115,7 +124,7 @@ private void Move(Uri currentContextUri, Uri source, Uri destination, string sou { sourceUrl = $"{source.Scheme}://{source.Host}/{sourceUrl.TrimStart('/')}"; } - if (!targetUrl.StartsWith(destination.ToString())) + if (!targetUrl.StartsWith("https://") && !targetUrl.StartsWith(destination.ToString())) { targetUrl = $"{destination.Scheme}://{destination.Host}/{targetUrl.TrimStart('/')}"; }