This commit is contained in:
Dev
2026-05-28 17:51:45 +02:00
@@ -246,9 +246,6 @@ public class FileTransferService : IFileTransferService
var streamResult = srcFile.OpenBinaryStream(); var streamResult = srcFile.OpenBinaryStream();
await ExecuteQueryRetryHelper.ExecuteQueryRetryAsync(sourceCtx, progress, ct); await ExecuteQueryRetryHelper.ExecuteQueryRetryAsync(sourceCtx, progress, ct);
if (streamResult.Value == null)
throw new InvalidOperationException($"Could not open binary stream for: {srcFileUrl}");
using var buffer = new MemoryStream(); using var buffer = new MemoryStream();
await streamResult.Value.CopyToAsync(buffer, 81920, ct); await streamResult.Value.CopyToAsync(buffer, 81920, ct);
buffer.Position = 0; buffer.Position = 0;
@@ -257,8 +254,6 @@ public class FileTransferService : IFileTransferService
// streams the payload in one request and does not touch list-view // streams the payload in one request and does not touch list-view
// metadata, so it bypasses LVT. // metadata, so it bypasses LVT.
var slash = effectiveDestUrl.LastIndexOf('/'); var slash = effectiveDestUrl.LastIndexOf('/');
if (slash < 0)
throw new InvalidOperationException($"Invalid destination URL (no slash): {effectiveDestUrl}");
var destFolderUrl = effectiveDestUrl.Substring(0, slash); var destFolderUrl = effectiveDestUrl.Substring(0, slash);
var destFileName = effectiveDestUrl.Substring(slash + 1); var destFileName = effectiveDestUrl.Substring(slash + 1);
@@ -278,20 +273,8 @@ public class FileTransferService : IFileTransferService
// successful upload to honour Move semantics. // successful upload to honour Move semantics.
var srcDelete = sourceCtx.Web.GetFileByServerRelativeUrl(srcFileUrl); var srcDelete = sourceCtx.Web.GetFileByServerRelativeUrl(srcFileUrl);
srcDelete.DeleteObject(); srcDelete.DeleteObject();
try
{
await ExecuteQueryRetryHelper.ExecuteQueryRetryAsync(sourceCtx, progress, ct); await ExecuteQueryRetryHelper.ExecuteQueryRetryAsync(sourceCtx, progress, ct);
} }
catch (OperationCanceledException) { throw; }
catch (Exception ex)
{
Log.Error(ex,
"Move: source delete failed for {Src} after successful upload to {Dst}. " +
"File is duplicated — manually delete the source.",
srcFileUrl, effectiveDestUrl);
throw;
}
}
} }
/// <summary> /// <summary>
@@ -347,10 +330,8 @@ public class FileTransferService : IFileTransferService
await ExecuteQueryRetryHelper.ExecuteQueryRetryAsync(ctx, progress, ct); await ExecuteQueryRetryHelper.ExecuteQueryRetryAsync(ctx, progress, ct);
return file.Exists; return file.Exists;
} }
catch (OperationCanceledException) { throw; } catch
catch (Exception ex)
{ {
Log.Debug("File existence check failed for {Url}: {Error}", fileServerRelativeUrl, ex.Message);
return false; return false;
} }
} }
@@ -457,7 +438,6 @@ public class FileTransferService : IFileTransferService
await ExecuteQueryRetryHelper.ExecuteQueryRetryAsync(ctx, progress, ct); await ExecuteQueryRetryHelper.ExecuteQueryRetryAsync(ctx, progress, ct);
return list.ItemCount; return list.ItemCount;
} }
catch (OperationCanceledException) { throw; }
catch (Exception ex) catch (Exception ex)
{ {
// Non-fatal: pre-flight count is purely informational. Treat as // Non-fatal: pre-flight count is purely informational. Treat as