Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CopyFile Improvement #11798

Merged
merged 3 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/Libraries/CoreNodes/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,28 @@ public static void DeleteFile(string path)
/// Copies a file.
/// </summary>
/// <param name="file">File object to copy</param>
/// <param name="destinationPath">String representation of destination path</param>
/// <param name="destinationPath">String representation of destination file path</param>
/// <param name="overwrite">Toggle to overwrite existing files</param>
/// <returns name="void">Node performs a task, doesn’t produce an output </returns>
public static void CopyFile(FileInfo file, string destinationPath, bool overwrite = false)
/// <returns name="bool">Node performs a task, return true of copy action succeed.</returns>
public static bool CopyFile(FileInfo file, string destinationPath, bool overwrite = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QilongTang this change likely means that any c# packages which called this function from a ZT node will need to be recompiled.

That probably is a very small number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reminder! @mjkkirschner

{
file.CopyTo(destinationPath, overwrite);
try
{
if (Path.GetDirectoryName(destinationPath) != string.Empty && FileExtension(destinationPath) != string.Empty)
{
file.CopyTo(destinationPath, overwrite);
}
else
{
throw new FileNotFoundException(Properties.Resources.InvalidDestinationPathErrorMessage, destinationPath);
}
}
catch (System.Exception ex)
{
throw ex;
}
return true;

}

/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Libraries/CoreNodes/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Libraries/CoreNodes/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
<data name="IntegerOverflow" xml:space="preserve">
<value>The operation resulted in an integer overflow. Its result may be unexpected.</value>
</data>
<data name="InvalidDestinationPathErrorMessage" xml:space="preserve">
<value>Invalid destination file path used as copy path.</value>
</data>
<data name="InvalidKeysErrorMessage" xml:space="preserve">
<value>One or more input types are not matching. Lists as keys are not supported.</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Libraries/CoreNodes/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
<data name="IntegerOverflow" xml:space="preserve">
<value>The operation resulted in an integer overflow. Its result may be unexpected.</value>
</data>
<data name="InvalidDestinationPathErrorMessage" xml:space="preserve">
<value>Invalid destination file path used as copy path.</value>
</data>
<data name="InvalidKeysErrorMessage" xml:space="preserve">
<value>One or more input types are not matching. Lists as keys are not supported.</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion test/Libraries/CoreNodesTests/FileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void File_Copy()

var dest = GetNewFileNameOnTempPath(".txt");
var destInfo = FileSystem.FileFromPath(dest);
FileSystem.CopyFile(fnInfo, dest);
Assert.IsTrue(FileSystem.CopyFile(fnInfo, dest));
Assert.IsTrue(System.IO.File.Exists(dest));
Assert.IsTrue(System.IO.File.Exists(fn));
Assert.AreEqual(contents, FileSystem.ReadText(fnInfo));
Expand Down