mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
Ignore Mac metadata hidden files ._* (#443)
* Implemented the ability to completely ignore all MacOS ._ files. They are ignored for all I/O operations (on all OSes)
This commit is contained in:
parent
a349f16ed4
commit
434bcdae4c
@ -16,6 +16,7 @@ namespace API.Parser
|
|||||||
public const string ImageFileExtensions = @"^(\.png|\.jpeg|\.jpg)";
|
public const string ImageFileExtensions = @"^(\.png|\.jpeg|\.jpg)";
|
||||||
public const string ArchiveFileExtensions = @"\.cbz|\.zip|\.rar|\.cbr|\.tar.gz|\.7zip|\.7z|\.cb7|\.cbt";
|
public const string ArchiveFileExtensions = @"\.cbz|\.zip|\.rar|\.cbr|\.tar.gz|\.7zip|\.7z|\.cb7|\.cbt";
|
||||||
public const string BookFileExtensions = @"\.epub|\.pdf";
|
public const string BookFileExtensions = @"\.epub|\.pdf";
|
||||||
|
public const string MacOsMetadataFileStartsWith = @"._";
|
||||||
|
|
||||||
public const string SupportedExtensions =
|
public const string SupportedExtensions =
|
||||||
ArchiveFileExtensions + "|" + ImageFileExtensions + "|" + BookFileExtensions;
|
ArchiveFileExtensions + "|" + ImageFileExtensions + "|" + BookFileExtensions;
|
||||||
|
@ -117,7 +117,8 @@ namespace API.Services
|
|||||||
{
|
{
|
||||||
var result = entryFullNames
|
var result = entryFullNames
|
||||||
.FirstOrDefault(x => !Path.EndsInDirectorySeparator(x) && !Parser.Parser.HasBlacklistedFolderInPath(x)
|
.FirstOrDefault(x => !Path.EndsInDirectorySeparator(x) && !Parser.Parser.HasBlacklistedFolderInPath(x)
|
||||||
&& Parser.Parser.IsCoverImage(x));
|
&& Parser.Parser.IsCoverImage(x)
|
||||||
|
&& !x.StartsWith(Parser.Parser.MacOsMetadataFileStartsWith));
|
||||||
|
|
||||||
return string.IsNullOrEmpty(result) ? null : result;
|
return string.IsNullOrEmpty(result) ? null : result;
|
||||||
}
|
}
|
||||||
@ -131,7 +132,8 @@ namespace API.Services
|
|||||||
{
|
{
|
||||||
var result = entryFullNames.OrderBy(Path.GetFileName, _comparer)
|
var result = entryFullNames.OrderBy(Path.GetFileName, _comparer)
|
||||||
.FirstOrDefault(x => !Parser.Parser.HasBlacklistedFolderInPath(x)
|
.FirstOrDefault(x => !Parser.Parser.HasBlacklistedFolderInPath(x)
|
||||||
&& Parser.Parser.IsImage(x));
|
&& Parser.Parser.IsImage(x)
|
||||||
|
&& !x.StartsWith(Parser.Parser.MacOsMetadataFileStartsWith));
|
||||||
|
|
||||||
return string.IsNullOrEmpty(result) ? null : result;
|
return string.IsNullOrEmpty(result) ? null : result;
|
||||||
}
|
}
|
||||||
@ -295,7 +297,11 @@ namespace API.Services
|
|||||||
{
|
{
|
||||||
foreach (var entry in entries)
|
foreach (var entry in entries)
|
||||||
{
|
{
|
||||||
if (Path.GetFileNameWithoutExtension(entry.Key).ToLower().EndsWith("comicinfo") && !Parser.Parser.HasBlacklistedFolderInPath(entry.Key) && Parser.Parser.IsXml(entry.Key))
|
var filename = Path.GetFileNameWithoutExtension(entry.Key).ToLower();
|
||||||
|
if (filename.EndsWith("comicinfo")
|
||||||
|
&& !filename.StartsWith(Parser.Parser.MacOsMetadataFileStartsWith)
|
||||||
|
&& !Parser.Parser.HasBlacklistedFolderInPath(entry.Key)
|
||||||
|
&& Parser.Parser.IsXml(entry.Key))
|
||||||
{
|
{
|
||||||
using var ms = StreamManager.GetStream();
|
using var ms = StreamManager.GetStream();
|
||||||
entry.WriteTo(ms);
|
entry.WriteTo(ms);
|
||||||
@ -328,7 +334,10 @@ namespace API.Services
|
|||||||
{
|
{
|
||||||
_logger.LogDebug("Using default compression handling");
|
_logger.LogDebug("Using default compression handling");
|
||||||
using var archive = ZipFile.OpenRead(archivePath);
|
using var archive = ZipFile.OpenRead(archivePath);
|
||||||
var entry = archive.Entries.SingleOrDefault(x => !Parser.Parser.HasBlacklistedFolderInPath(x.FullName) && Path.GetFileNameWithoutExtension(x.Name).ToLower() == "comicinfo" && Parser.Parser.IsXml(x.FullName));
|
var entry = archive.Entries.SingleOrDefault(x => !Parser.Parser.HasBlacklistedFolderInPath(x.FullName)
|
||||||
|
&& Path.GetFileNameWithoutExtension(x.Name).ToLower() == "comicinfo"
|
||||||
|
&& !Path.GetFileNameWithoutExtension(x.Name).StartsWith(Parser.Parser.MacOsMetadataFileStartsWith)
|
||||||
|
&& Parser.Parser.IsXml(x.FullName));
|
||||||
if (entry != null)
|
if (entry != null)
|
||||||
{
|
{
|
||||||
using var stream = entry.Open();
|
using var stream = entry.Open();
|
||||||
@ -343,6 +352,7 @@ namespace API.Services
|
|||||||
using var archive = ArchiveFactory.Open(archivePath);
|
using var archive = ArchiveFactory.Open(archivePath);
|
||||||
info = FindComicInfoXml(archive.Entries.Where(entry => !entry.IsDirectory
|
info = FindComicInfoXml(archive.Entries.Where(entry => !entry.IsDirectory
|
||||||
&& !Parser.Parser.HasBlacklistedFolderInPath(Path.GetDirectoryName(entry.Key) ?? string.Empty)
|
&& !Parser.Parser.HasBlacklistedFolderInPath(Path.GetDirectoryName(entry.Key) ?? string.Empty)
|
||||||
|
&& !Path.GetFileNameWithoutExtension(entry.Key).StartsWith(Parser.Parser.MacOsMetadataFileStartsWith)
|
||||||
&& Parser.Parser.IsXml(entry.Key)));
|
&& Parser.Parser.IsXml(entry.Key)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ namespace API.Services
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Given a set of regex search criteria, get files in the given path.
|
/// Given a set of regex search criteria, get files in the given path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>This will always exclude <see cref="Parser.Parser.MacOsMetadataFileStartsWith"/> patterns</remarks>
|
||||||
/// <param name="path">Directory to search</param>
|
/// <param name="path">Directory to search</param>
|
||||||
/// <param name="searchPatternExpression">Regex version of search pattern (ie \.mp3|\.mp4). Defaults to * meaning all files.</param>
|
/// <param name="searchPatternExpression">Regex version of search pattern (ie \.mp3|\.mp4). Defaults to * meaning all files.</param>
|
||||||
/// <param name="searchOption">SearchOption to use, defaults to TopDirectoryOnly</param>
|
/// <param name="searchOption">SearchOption to use, defaults to TopDirectoryOnly</param>
|
||||||
@ -35,9 +36,10 @@ namespace API.Services
|
|||||||
{
|
{
|
||||||
if (!Directory.Exists(path)) return ImmutableList<string>.Empty;
|
if (!Directory.Exists(path)) return ImmutableList<string>.Empty;
|
||||||
var reSearchPattern = new Regex(searchPatternExpression, RegexOptions.IgnoreCase);
|
var reSearchPattern = new Regex(searchPatternExpression, RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
return Directory.EnumerateFiles(path, "*", searchOption)
|
return Directory.EnumerateFiles(path, "*", searchOption)
|
||||||
.Where(file =>
|
.Where(file =>
|
||||||
reSearchPattern.IsMatch(Path.GetExtension(file)));
|
reSearchPattern.IsMatch(Path.GetExtension(file)) && !Path.GetFileName(file).StartsWith(Parser.Parser.MacOsMetadataFileStartsWith));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,7 +100,7 @@ namespace API.Services
|
|||||||
var reSearchPattern = new Regex(searchPatternExpression, RegexOptions.IgnoreCase);
|
var reSearchPattern = new Regex(searchPatternExpression, RegexOptions.IgnoreCase);
|
||||||
return Directory.EnumerateFiles(path, "*", searchOption)
|
return Directory.EnumerateFiles(path, "*", searchOption)
|
||||||
.Where(file =>
|
.Where(file =>
|
||||||
reSearchPattern.IsMatch(file));
|
reSearchPattern.IsMatch(file) && !file.StartsWith(Parser.Parser.MacOsMetadataFileStartsWith));
|
||||||
}
|
}
|
||||||
|
|
||||||
return !Directory.Exists(path) ? Array.Empty<string>() : Directory.GetFiles(path);
|
return !Directory.Exists(path) ? Array.Empty<string>() : Directory.GetFiles(path);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<Company>kavitareader.com</Company>
|
<Company>kavitareader.com</Company>
|
||||||
<Product>Kavita</Product>
|
<Product>Kavita</Product>
|
||||||
<AssemblyVersion>0.4.3.3</AssemblyVersion>
|
<AssemblyVersion>0.4.3.4</AssemblyVersion>
|
||||||
<NeutralLanguage>en</NeutralLanguage>
|
<NeutralLanguage>en</NeutralLanguage>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user