-fix Copy to Tapecatalog

- only use relative paths
This commit is contained in:
Black_Betty committed 2026-10-05 21:24:28 +02:00
1 parent a3b41679c9
commit 7550cab2c5
3 files changed
+50 -10

No files matched your search

+26 -4
View File
@@ -87,13 +87,24 @@ namespace TapeCatalog.Methods
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException("path");
if (!Directory.Exists(path)) throw new DirectoryNotFoundException(path);
// normalize source root for reliable relative path calculation
var rootFull = System.IO.Path.GetFullPath(path).TrimEnd(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar);
foreach (var file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories))
{
try
{
var fi = new FileInfo(file);
// compute directory relative to source root (remove the source root prefix)
var dirFull = System.IO.Path.GetFullPath(fi.DirectoryName).TrimEnd(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar);
string relativeDir = string.Empty;
if (dirFull.StartsWith(rootFull, StringComparison.OrdinalIgnoreCase))
relativeDir = dirFull.Length == rootFull.Length ? string.Empty : dirFull.Substring(rootFull.Length).TrimStart(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar);
else
relativeDir = fi.DirectoryName;
var existing = files.FirstOrDefault(f => string.Equals(f.Filename, fi.Name, StringComparison.OrdinalIgnoreCase)
&& string.Equals(f.FileDir, fi.DirectoryName, StringComparison.OrdinalIgnoreCase));
&& string.Equals(f.FileDir, relativeDir, StringComparison.OrdinalIgnoreCase));
if (existing != null)
{
var newSizeMb = FormatBytesToMb(fi.Length);
@@ -110,7 +121,7 @@ namespace TapeCatalog.Methods
files.Add(new TapeCatalog.FileEntry
{
Filename = fi.Name,
FileDir = fi.DirectoryName,
FileDir = relativeDir,
SizeSrc = FormatBytesToMb(fi.Length),
ModSrc = fi.LastWriteTime.ToString(),
});
@@ -128,13 +139,24 @@ namespace TapeCatalog.Methods
{
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException("path");
if (!Directory.Exists(path)) throw new DirectoryNotFoundException(path);
// normalize archive root for reliable relative path calculation
var rootFull = System.IO.Path.GetFullPath(path).TrimEnd(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar);
foreach (var file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories))
{
try
{
var fi = new FileInfo(file);
var existing = files.FirstOrDefault(f => string.Equals(f.Filename, fi.Name, StringComparison.Ordinal));
var dirFull = System.IO.Path.GetFullPath(fi.DirectoryName).TrimEnd(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar);
string relativeDir = string.Empty;
if (dirFull.StartsWith(rootFull, StringComparison.OrdinalIgnoreCase))
relativeDir = dirFull.Length == rootFull.Length ? string.Empty : dirFull.Substring(rootFull.Length).TrimStart(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar);
else
relativeDir = fi.DirectoryName;
var existing = files.FirstOrDefault(f => string.Equals(f.Filename, fi.Name, StringComparison.Ordinal)
&& string.Equals(f.FileDir, relativeDir, StringComparison.OrdinalIgnoreCase));
if (existing != null)
{
existing.SizeArc = FormatBytesToMb(fi.Length);
@@ -148,7 +170,7 @@ namespace TapeCatalog.Methods
files.Add(new TapeCatalog.FileEntry
{
Filename = fi.Name,
FileDir = fi.DirectoryName,
FileDir = relativeDir,
SizeArc = FormatBytesToMb(fi.Length),
ModArc = fi.LastWriteTime.ToString()
});