Skip to content

Commit

Permalink
Pull a trick to handle filenames with any of <>:"/\|?*.
Browse files Browse the repository at this point in the history
xdelta3 in Windows, as of v3.0.11, can't access any file with any of <>:"/\|?* in filename.
These are full-width (fixed-width) characters, not the forbidden ASCII ones, so valid for filenames.
Check if the trick is needed -> copy source & target file -> run xdelta3 with these temporary files as inputs -> del temp files
  • Loading branch information
dreamer2908 committed May 2, 2016
1 parent 8a6450f commit 0179b3d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions YAXBPC/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,26 @@ private void createPatch(string _sourceFile, string _targetFile, string _outDir)
string targetFile = _targetFile;
string outputDir = _outDir;
string outputVcdiff = Path.Combine(outputDir, "changes.vcdiff");
bool plsDelSourceFile = false;
bool plsDelTargetFile = false;

if (runningInWindows)
{
if (sourceFile.IndexOfAny("<>:"/\|?*".ToCharArray()) != -1)
{
string tmpFname = Path.GetRandomFileName();
File.Copy(sourceFile, tmpFname, true);
sourceFile = tmpFname;
plsDelSourceFile = true;
}
if (targetFile.IndexOfAny("<>:"/\|?*".ToCharArray()) != -1)
{
string tmpFname = Path.GetRandomFileName();
File.Copy(targetFile, tmpFname, true);
targetFile = tmpFname;
plsDelTargetFile = true;
}
}

Process xdelta = new Process();
if (runningInWindows && run64bitxdelta) xdelta.StartInfo.FileName = "xdelta3.x86_64.exe";
Expand Down Expand Up @@ -462,6 +482,15 @@ private void createPatch(string _sourceFile, string _targetFile, string _outDir)
xdelta.WaitForExit();
if (debugMode) MessageBox.Show(sb.ToString());

if (plsDelSourceFile)
{
File.Delete(sourceFile);
}
if (plsDelTargetFile)
{
File.Delete(targetFile);
}

if (xdelta.ExitCode != 0) // I, right here, abuse exception. Feel free to sue me.
{
throw new Exception(sb.ToString().Trim());
Expand Down

0 comments on commit 0179b3d

Please sign in to comment.