Skip to content

Commit

Permalink
Resolves #792 Downloaded language sometimes cannot be deleted when us…
Browse files Browse the repository at this point in the history
…ing SQLite.

Avoids DirectoryNotFoundException when deleting non existing sitemap folder.
  • Loading branch information
mgesing committed Aug 24, 2023
1 parent f546a36 commit 6abd22a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Fixed localized properties were not updated during import.
- Localized SeName was only updated when import file also contained a non-localized SeName column.
- Fixed MainPictureId not applied on product edit page if missing and if there is only one picture assigned to a product.
- Resolves #792 Downloaded language sometimes cannot be deleted when using SQLite.


## Smartstore 5.0.5
Expand Down
10 changes: 7 additions & 3 deletions src/Smartstore.Core/Platform/Seo/Services/XmlSitemapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,14 @@ public virtual void Invalidate(int storeId, int? languageId)
public virtual void InvalidateAll()
{
var dir = BuildSitemapDirPath(null, null);
foreach (var subDir in _tenantRoot.EnumerateDirectories(dir).ToArray())

if (_tenantRoot.DirectoryExists(dir))
{
// Delete only directories, no lock files.
subDir.Delete();
foreach (var subDir in _tenantRoot.EnumerateDirectories(dir).ToArray())
{
// Delete only directories, no lock files.
subDir.Delete();
}
}
}

Expand Down
21 changes: 18 additions & 3 deletions src/Smartstore.Web/Areas/Admin/Controllers/LanguageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,31 @@ public async Task<IActionResult> Delete(int id)
}

// Ensure we have at least one published language
var allLanguages = _languageService.GetAllLanguages();
var allLanguages = await _languageService.GetAllLanguagesAsync();
if (allLanguages.Count == 1 && allLanguages[0].Id == language.Id)
{
NotifyError(T("Admin.Configuration.Languages.OnePublishedLanguageRequired"));

return RedirectToAction(nameof(Edit), new { id = language.Id });
}

_db.Languages.Remove(language);
await _db.SaveChangesAsync();
for (var i = 1; i <= 2; i++)
{
try
{
_db.Languages.Remove(language);
await _db.SaveChangesAsync();
break;
}
catch
{
// SQLite sometimes throws "Database disk image is malformed". After database shrink it works.
if (_db.DataProvider.ProviderType == DbSystemType.SQLite && _db.DataProvider.CanShrink)
{
await _db.DataProvider.ShrinkDatabaseAsync(false);
}
}
}

NotifySuccess(T("Admin.Configuration.Languages.Deleted"));

Expand Down

0 comments on commit 6abd22a

Please sign in to comment.