Browse Source

Merge pull request #26160 from abpframework/auto-merge-forward/rel-10.7-to-dev-42

Auto-merge forward rel-10.7 → dev
pull/26163/head
Yağmur Çelik 3 weeks ago
committed by GitHub
parent
commit
f762bc0785
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/AbpAspNetCoreModule.cs
  2. 38
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs

8
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/AbpAspNetCoreModule.cs

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.DependencyInjection;
using Volo.Abp.AspNetCore.Auditing; using Volo.Abp.AspNetCore.Auditing;
using Volo.Abp.AspNetCore.VirtualFileSystem; using Volo.Abp.AspNetCore.VirtualFileSystem;
@ -64,7 +65,14 @@ public class AbpAspNetCoreModule : AbpModule
context.Services.AddObjectAccessor<IEndpointRouteBuilder>(); context.Services.AddObjectAccessor<IEndpointRouteBuilder>();
context.Services.AddAbpDynamicOptions<RequestLocalizationOptions, AbpRequestLocalizationOptionsManager>(); context.Services.AddAbpDynamicOptions<RequestLocalizationOptions, AbpRequestLocalizationOptionsManager>();
try
{
StaticWebAssetsLoader.UseStaticWebAssets(context.Services.GetHostingEnvironment(), context.Services.GetConfiguration()); StaticWebAssetsLoader.UseStaticWebAssets(context.Services.GetHostingEnvironment(), context.Services.GetConfiguration());
}
catch (Exception ex)
{
context.Services.GetInitLogger<AbpAspNetCoreModule>().LogWarning(ex, "Could not load the static web assets manifest, static web assets will not be available. This usually happens when the application runs with build output instead of publish output.");
}
context.Services.AddHttpUserAgentCachedParser(); context.Services.AddHttpUserAgentCachedParser();
} }

38
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs

@ -406,11 +406,14 @@ public class VoloNugetPackagesVersionUpdater : ITransientDependency
try try
{ {
using (var fs = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) string fileContent;
{ Encoding detectedEncoding;
using (var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var sr = new StreamReader(fs, DefaultEncoding, true)) using (var sr = new StreamReader(fs, DefaultEncoding, true))
{ {
var fileContent = await sr.ReadToEndAsync(); fileContent = await sr.ReadToEndAsync();
detectedEncoding = sr.CurrentEncoding;
}
var doc = new XmlDocument { PreserveWhitespace = true }; var doc = new XmlDocument { PreserveWhitespace = true };
doc.LoadXml(fileContent); doc.LoadXml(fileContent);
@ -449,24 +452,35 @@ public class VoloNugetPackagesVersionUpdater : ITransientDependency
} }
} }
fs.Seek(0, SeekOrigin.Begin); var updatedXml = doc.OuterXml;
fs.SetLength(0);
using (var sw = new StreamWriter(fs, DefaultEncoding)) // Write to a temp file in the same directory and atomically swap it in with
// File.Replace, instead of truncating filePath in place - this way a failure
// mid-write (disk full, process killed) never leaves the original file empty
// or partially written; it either stays untouched or is fully replaced.
var tempFilePath = Path.Combine(Path.GetDirectoryName(filePath) ?? string.Empty, Path.GetRandomFileName());
try
{
using (var tempStream = new FileStream(tempFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.None))
using (var sw = new StreamWriter(tempStream, detectedEncoding))
{ {
await sw.WriteAsync(doc.OuterXml); await sw.WriteAsync(updatedXml);
await sw.FlushAsync(); await sw.FlushAsync();
} }
File.Replace(tempFilePath, filePath, null);
}
finally
{
if (File.Exists(tempFilePath))
{
File.Delete(tempFilePath);
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
// The file is truncated before the updated XML is written back, so a failure here Logger.LogError(ex, "Failed to update central package versions in \"{FilePath}\".", filePath);
// (disk full, process killed, file locked mid-write) can leave it empty/partially
// written on disk. Logged as an error (not a warning) so this isn't missed - the
// rest of the switch-to-nightly run still continues for other solutions/files.
Logger.LogError(ex, "Failed to update central package versions in \"{FilePath}\". The file may now be empty or partially written - please check it manually.", filePath);
} }
} }
} }

Loading…
Cancel
Save