mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-01-06 12:00:26 -06:00
fixing copy file
This commit is contained in:
@@ -77,8 +77,10 @@ namespace FileFlows.BasicNodes.File
|
|||||||
}
|
}
|
||||||
args.Logger.ILog($"CopyFile.Dest[5] '{dest}'");
|
args.Logger.ILog($"CopyFile.Dest[5] '{dest}'");
|
||||||
|
|
||||||
var destDir = new FileInfo(dest).DirectoryName;
|
// cant use new FileInfo(dest).Directory.Name here since
|
||||||
args.CreateDirectoryIfNotExists(destDir ?? String.Empty);
|
// if the folder is a linux folder and this node is running on windows
|
||||||
|
// /mnt, etc will be converted to c:\mnt and break the destination
|
||||||
|
var destDir = dest.Substring(0, dest.Replace("\\", "/").LastIndexOf("/"));
|
||||||
|
|
||||||
if(string.IsNullOrEmpty(DestinationFile) == false)
|
if(string.IsNullOrEmpty(DestinationFile) == false)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,17 +6,25 @@ namespace BasicNodes.Tests;
|
|||||||
|
|
||||||
using FileFlows.BasicNodes.File;
|
using FileFlows.BasicNodes.File;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class CopyTests
|
public class CopyTests
|
||||||
{
|
{
|
||||||
|
List<KeyValuePair<string, string>> Mappings = new List<KeyValuePair<string, string>>
|
||||||
|
{
|
||||||
|
new KeyValuePair<string, string>("/usr/local/bin/ffmpeg", @"C:\Users\username\AppData\Roaming\FileFlows\Tools\ffmpeg.exe"),
|
||||||
|
new KeyValuePair<string, string>("/mnt/tempNAS/media/dvd/sorted", @"\\192.168.1.22\Media\dvd\sorted"),
|
||||||
|
new KeyValuePair<string, string>("/mnt/tempNAS/media/dvd/output", @"\\192.168.1.22\Media\dvd\output"),
|
||||||
|
};
|
||||||
|
char DirectorySeperatorChar = System.IO.Path.DirectorySeparatorChar;
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CopyTests_Dir_Mapping()
|
public void CopyTests_Dir_Mapping()
|
||||||
{
|
{
|
||||||
var logger = new TestLogger();
|
var logger = new TestLogger();
|
||||||
var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", logger, false, string.Empty);
|
var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", logger, false, string.Empty);
|
||||||
args.PathMapper = s => s;
|
args.PathMapper = s => Map(s);
|
||||||
|
|
||||||
CopyFile node = new ();
|
CopyFile node = new ();
|
||||||
node.CopyFolder = true;
|
node.CopyFolder = true;
|
||||||
@@ -26,6 +34,31 @@ public class CopyTests
|
|||||||
Assert.AreEqual(2, result);
|
Assert.AreEqual(2, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string Map(string path)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(path))
|
||||||
|
return string.Empty;
|
||||||
|
if (Mappings != null && Mappings.Count > 0)
|
||||||
|
{
|
||||||
|
// convert all \ to / for now
|
||||||
|
path = path.Replace("\\", "/");
|
||||||
|
foreach (var mapping in Mappings)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(mapping.Value) || string.IsNullOrEmpty(mapping.Key))
|
||||||
|
continue;
|
||||||
|
string pattern = Regex.Escape(mapping.Key.Replace("\\", "/"));
|
||||||
|
string replacement = mapping.Value.Replace("\\", "/");
|
||||||
|
path = Regex.Replace(path, "^" + pattern, replacement, RegexOptions.IgnoreCase);
|
||||||
|
}
|
||||||
|
// now convert / to path charcter
|
||||||
|
if (DirectorySeperatorChar != '/')
|
||||||
|
path = path.Replace('/', DirectorySeperatorChar);
|
||||||
|
if (path.StartsWith("//")) // special case for SMB paths
|
||||||
|
path = path.Replace('/', '\\');
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user