Skip to content

Commit

Permalink
Fix #3215 : issue with copy file/folder when moving to personal or mu…
Browse files Browse the repository at this point in the history
…lti-geo environments
  • Loading branch information
Gautam Sheth authored and KoenZomers committed Sep 3, 2023
1 parent 7d3ee51 commit f7fcfd5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions src/Commands/Files/CopyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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))
{
Expand Down Expand Up @@ -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('/')}";
}
Expand Down
15 changes: 12 additions & 3 deletions src/Commands/Files/MoveFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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))
{
Expand Down Expand Up @@ -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('/')}";
}
Expand Down

0 comments on commit f7fcfd5

Please sign in to comment.