fix issue when penumbra mod folder contains a part of the path of cache folder
This commit is contained in:
@@ -61,7 +61,7 @@ public class FileDbManager
|
||||
|
||||
if (matchingEntries == null)
|
||||
{
|
||||
return CreateFileCacheEntity(path);
|
||||
return CreateFileEntry(path);
|
||||
}
|
||||
|
||||
var validatedCacheEntry = GetValidatedFileCache(matchingEntries);
|
||||
@@ -69,20 +69,33 @@ public class FileDbManager
|
||||
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);
|
||||
if (!fi.Exists) return null;
|
||||
string prefixedPath = fi.FullName.ToLowerInvariant().Replace(_ipcManager.PenumbraModDirectory()!.ToLowerInvariant(), PenumbraPrefix + "\\")
|
||||
.Replace(_configuration.CacheFolder.ToLowerInvariant(), CachePrefix + "\\").Replace("\\\\", "\\");
|
||||
var hash = Crypto.GetFileHash(path);
|
||||
string prefixedPath = fi.FullName.ToLowerInvariant().Replace(_configuration.CacheFolder.ToLowerInvariant(), CachePrefix + "\\").Replace("\\\\", "\\");
|
||||
return CreateFileCacheEntity(fi, prefixedPath);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
var entity = new FileCacheEntity();
|
||||
entity.Hash = hash;
|
||||
entity.Filepath = prefixedPath;
|
||||
entity.LastModifiedDate = fi.LastWriteTimeUtc.Ticks.ToString(CultureInfo.InvariantCulture);
|
||||
entity.LastModifiedDate = fileInfo.LastWriteTimeUtc.Ticks.ToString(CultureInfo.InvariantCulture);
|
||||
try
|
||||
{
|
||||
using var db = new FileCacheContext();
|
||||
@@ -91,10 +104,12 @@ public class FileDbManager
|
||||
}
|
||||
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)
|
||||
|
||||
@@ -211,7 +211,8 @@ public class PeriodicFileScanner : IDisposable
|
||||
{
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Authors></Authors>
|
||||
<Company></Company>
|
||||
<Version>0.4.13</Version>
|
||||
<Version>0.4.14</Version>
|
||||
<Description></Description>
|
||||
<Copyright></Copyright>
|
||||
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
using Dalamud.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.FileCacheDB;
|
||||
using System.IO;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.Utils;
|
||||
using System.Text.RegularExpressions;
|
||||
using MareSynchronos.Managers;
|
||||
|
||||
@@ -42,7 +37,6 @@ namespace MareSynchronos.Models
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
var cache = fileDbManager.GetFileCacheByPath(ResolvedPath);
|
||||
cache ??= fileDbManager.CreateFileCacheEntity(ResolvedPath);
|
||||
Hash = cache.OriginalHash;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace MareSynchronos.WebAPI
|
||||
fi.LastWriteTime = RandomDayFunc().Invoke();
|
||||
try
|
||||
{
|
||||
_ = _fileDbManager.CreateFileCacheEntity(filePath);
|
||||
_ = _fileDbManager.CreateCacheEntry(filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user