fix issue when penumbra mod folder contains a part of the path of cache folder

This commit is contained in:
Stanley Dimant
2022-09-25 20:51:03 +02:00
parent 9142b2bee4
commit afb1cf1429
5 changed files with 29 additions and 19 deletions

View File

@@ -61,7 +61,7 @@ public class FileDbManager
if (matchingEntries == null) if (matchingEntries == null)
{ {
return CreateFileCacheEntity(path); return CreateFileEntry(path);
} }
var validatedCacheEntry = GetValidatedFileCache(matchingEntries); var validatedCacheEntry = GetValidatedFileCache(matchingEntries);
@@ -69,20 +69,33 @@ public class FileDbManager
return validatedCacheEntry; return validatedCacheEntry;
} }
public FileCache? CreateFileCacheEntity(string path) public FileCache? CreateCacheEntry(string path)
{ {
Logger.Verbose("Creating entry for " + path); Logger.Debug("Creating cache entry for " + path);
FileInfo fi = new FileInfo(path); FileInfo fi = new FileInfo(path);
if (!fi.Exists) return null; if (!fi.Exists) return null;
string prefixedPath = fi.FullName.ToLowerInvariant().Replace(_ipcManager.PenumbraModDirectory()!.ToLowerInvariant(), PenumbraPrefix + "\\") string prefixedPath = fi.FullName.ToLowerInvariant().Replace(_configuration.CacheFolder.ToLowerInvariant(), CachePrefix + "\\").Replace("\\\\", "\\");
.Replace(_configuration.CacheFolder.ToLowerInvariant(), CachePrefix + "\\").Replace("\\\\", "\\"); return CreateFileCacheEntity(fi, prefixedPath);
var hash = Crypto.GetFileHash(path); }
public FileCache? CreateFileEntry(string path)
{
Logger.Debug("Creating file entry for " + path);
FileInfo fi = new FileInfo(path);
if (!fi.Exists) return null;
string prefixedPath = fi.FullName.ToLowerInvariant().Replace(_ipcManager.PenumbraModDirectory()!.ToLowerInvariant(), PenumbraPrefix + "\\").Replace("\\\\", "\\");
return CreateFileCacheEntity(fi, prefixedPath);
}
private FileCache? CreateFileCacheEntity(FileInfo fileInfo, string prefixedPath)
{
var hash = Crypto.GetFileHash(fileInfo.FullName);
lock (_lock) lock (_lock)
{ {
var entity = new FileCacheEntity(); var entity = new FileCacheEntity();
entity.Hash = hash; entity.Hash = hash;
entity.Filepath = prefixedPath; entity.Filepath = prefixedPath;
entity.LastModifiedDate = fi.LastWriteTimeUtc.Ticks.ToString(CultureInfo.InvariantCulture); entity.LastModifiedDate = fileInfo.LastWriteTimeUtc.Ticks.ToString(CultureInfo.InvariantCulture);
try try
{ {
using var db = new FileCacheContext(); using var db = new FileCacheContext();
@@ -91,10 +104,12 @@ public class FileDbManager
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Warn("Could not add " + path); Logger.Warn("Could not add " + fileInfo.FullName);
} }
} }
return GetFileCacheByPath(prefixedPath)!; var result = GetFileCacheByPath(prefixedPath);
Logger.Debug("Creating file cache for " + fileInfo.FullName + " success: " + (result != null));
return result;
} }
private FileCache? GetValidatedFileCache(FileCacheEntity e) private FileCache? GetValidatedFileCache(FileCacheEntity e)

View File

@@ -211,7 +211,8 @@ public class PeriodicFileScanner : IDisposable
{ {
if (ct.IsCancellationRequested) return; if (ct.IsCancellationRequested) return;
_ = _fileDbManager.CreateFileCacheEntity(file.Key); var entry = _fileDbManager.CreateFileEntry(file.Key);
if (entry == null) _ = _fileDbManager.CreateCacheEntry(file.Key);
Interlocked.Increment(ref currentFileProgress); Interlocked.Increment(ref currentFileProgress);
}); });

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Authors></Authors> <Authors></Authors>
<Company></Company> <Company></Company>
<Version>0.4.13</Version> <Version>0.4.14</Version>
<Description></Description> <Description></Description>
<Copyright></Copyright> <Copyright></Copyright>
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl> <PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>

View File

@@ -1,13 +1,8 @@
using Dalamud.Logging; using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using MareSynchronos.FileCacheDB;
using System.IO;
using MareSynchronos.API; using MareSynchronos.API;
using MareSynchronos.Utils;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using MareSynchronos.Managers; using MareSynchronos.Managers;
@@ -42,7 +37,6 @@ namespace MareSynchronos.Models
_ = Task.Run(() => _ = Task.Run(() =>
{ {
var cache = fileDbManager.GetFileCacheByPath(ResolvedPath); var cache = fileDbManager.GetFileCacheByPath(ResolvedPath);
cache ??= fileDbManager.CreateFileCacheEntity(ResolvedPath);
Hash = cache.OriginalHash; Hash = cache.OriginalHash;
}); });
} }

View File

@@ -132,7 +132,7 @@ namespace MareSynchronos.WebAPI
fi.LastWriteTime = RandomDayFunc().Invoke(); fi.LastWriteTime = RandomDayFunc().Invoke();
try try
{ {
_ = _fileDbManager.CreateFileCacheEntity(filePath); _ = _fileDbManager.CreateCacheEntry(filePath);
} }
catch (Exception ex) catch (Exception ex)
{ {