Skip to content

Comments

Copy File step refactor#348

Open
kikimych wants to merge 6 commits intomasterfrom
copy_directory
Open

Copy File step refactor#348
kikimych wants to merge 6 commits intomasterfrom
copy_directory

Conversation

@kikimych
Copy link
Contributor

Copy File step can now copy directories

Copy link
Contributor

@johnny-keker johnny-keker left a comment

Choose a reason for hiding this comment

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

Interface is unusable.

image

Comment on lines -92 to -94
{B7222544-B13F-48C8-85E3-6BFD3D44702A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7222544-B13F-48C8-85E3-6BFD3D44702A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7222544-B13F-48C8-85E3-6BFD3D44702A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Copy link
Contributor

Choose a reason for hiding this comment

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

Changes in this file don't make sense. We simply moved this 3 lines 4 lines further. Please revert

<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet />
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this property?

<RemoveDir Directories="$(ProjectDir)..\$(ConfigurationName)"/>
</Target>
</Project> No newline at end of file
</Project>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this line in diff?

Comment on lines 97 to 102
var sendSize = Math.Min(bytesToSend, BUFFER_SIZE);

var readCount = reader.Read(buffer, 0, Convert.ToInt32(sendSize));

if (readCount == 0) throw new IOException("SendFileAsync file read error");

writer.Write(buffer, 0, readCount);

bytesToSend -= readCount;
Copy link
Contributor

Choose a reason for hiding this comment

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

Codestyle: why emptyline between every line of code?

Comment on lines 16 to 20
public string relativePath_ { get; set; }

public DateTime lastWriteTimeUtc_ { get; set; }

public bool isDirectory_ { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Codestyle: what case is this and why is it chosen?

Copy link
Contributor

@johnny-keker johnny-keker Feb 22, 2023

Choose a reason for hiding this comment

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

I believe we use PascalCase for public properties.

namespace VSRAD.DebugServer.SharedUtils
{

public class FileMetadata// : IEquatable<FileMetadata>
Copy link
Contributor

Choose a reason for hiding this comment

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

So IEquatable should not be implemented?

<Version>$([System.Text.RegularExpressions.Regex]::Match($([System.Text.RegularExpressions.Regex]::Match($([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)\..\VSRAD.Package\source.extension.vsixmanifest")), `Version=\"[0-9,.]+\" Language=`).ToString()),`[0-9,.]+`).ToString())</Version>
</PropertyGroup>
<Message Importance="High" Text="Debug server version: $(Version)"/>
<Message Importance="High" Text="Debug server version: $(Version)" />
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not need this line in diff.

@johnny-keker
Copy link
Contributor

johnny-keker commented Feb 22, 2023

Interface is unusable.

image

upd: fixed in 034f908

Copy link
Contributor

@johnny-keker johnny-keker left a comment

Choose a reason for hiding this comment

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

Project is not building in Release configuration

image

@johnny-keker
Copy link
Contributor

Project is not building in Release configuration

image

Looks like we need <AllowUnsafeBlocks>true</AllowUnsafeBlocks> in both Build and DebugServer

However, jumping ahead, I don't like using unsafe code at all. As far as I can see, we can refactor code to get rid of it. But I'm still investigating it

@johnny-keker
Copy link
Contributor

For example, EqualStartingCharacterCount can be rewritten in C# way, using Zip from Linq and simple foreach iterator.

@johnny-keker
Copy link
Contributor

@kikimych please consider f93be37

I believe this is much more laconic and simple implementation of same (am I right?) function without using unsafe code

Copy link
Contributor

@johnny-keker johnny-keker left a comment

Choose a reason for hiding this comment

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

Show stopper

Current manual approach to paths handling doesn't work for Windows host -> Linux remote situation. Next image illustrates problem, Windows host is on the left, Linux remote on the right

image

Personally I am not very fond of whole PathExtension.cs thing, I'll try to come out with better suggestion ASAP

Comment on lines 71 to 78
case SendFileCommand _:
var send_command = (SendFileCommand)command;
var sendPath = Path.Combine(send_command.SrcPath, send_command.Metadata.relativePath_);
return await SendFileAsync(writer, sendPath, send_command.UseCompression).ConfigureAwait(false);
case GetFileCommand _:
var receive_command = (GetFileCommand)command;
var receivePath = Path.Combine(receive_command.DstPath, receive_command.Metadata.relativePath_);
return await ReceiveFileAsync(writer, receivePath, receive_command.UseCompression);
Copy link
Contributor

Choose a reason for hiding this comment

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

In this chunk of code switch already does conversion for us, however we discard it using _, only to do it again manually in the next line. Also, we do not use snake case anywhere in project (as far as I know)

I suggest rewriting this switch like this:

case SendFileCommand sf:
    var sendPath = Path.Combine(sf.SrcPath, sf.Metadata.relativePath_);
    return await SendFileAsync(writer, sendPath, sf.UseCompression).ConfigureAwait(false);
case GetFileCommand gf:
    var receivePath = Path.Combine(gf.DstPath, gf.Metadata.relativePath_);
    return await ReceiveFileAsync(writer, receivePath, gf.UseCompression);
default:
    break;

Comment on lines +31 to +39
public String ToString()
{
var props = this.GetType().GetProperties();
var sb = new StringBuilder();
foreach (var p in props)
{
sb.AppendLine(p.Name + ": " + p.GetValue(this, null));
}
return sb.ToString();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to use reflection to iterate over 3 properties?

Also, readability can be improved. I would suggest maybe something more like

public override string ToString() => string.Join(Environment.NewLine, new string[]
{
    "Metadata = [",
    $"\tRelative Path       : {relativePath_}",
    $"\tLast Write Time UTC : {lastWriteTimeUtc_}",
    $"\tIs Directory        : {isDirectory_}",
    "]"
});

Comment on lines 310 to 313
private static XmlSerializer getFormatter()
{
return new XmlSerializer(typeof(List<FileMetadata>));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really don't have other options to serialize a List of FileMetadata but using XmlSerializer?

It seems off to me, since we never used such format before anywhere in project.

Also, this declaration clearly suggests that it was originated in some Java code, in C# we use PascalCase in such places.

@kikimych kikimych force-pushed the copy_directory branch 2 times, most recently from c7ba63e to efc0e20 Compare March 6, 2023 18:04
Copy link
Contributor

@johnny-keker johnny-keker left a comment

Choose a reason for hiding this comment

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

Checked new version with server on Ubuntu. Old problem (#348 (review)) is not resolved, and now I have a new problem when new directory path contain full windows path from host

image

Comment on lines +310 to +313
private static XmlSerializer GetFormatter()
{
return new XmlSerializer(typeof(List<FileMetadata>));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as #348 (comment)

Do we really need XmlSerializer?

@johnny-keker

This comment was marked as outdated.

@johnny-keker

This comment was marked as outdated.

{
var rootPath = Path.Combine(_environment.LocalWorkDir, step.SourcePath);
var localInfos = new List<FileMetadata>();
foreach (var info in PathExtension.TraverseFileInfoTree(rootPath))
Copy link
Contributor

Choose a reason for hiding this comment

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

This function will return an empty list in case we specified path of the particular file, and we won't send nothing. Expected behavior would be sending one specified file.

    Client handles server ststuses for file copy commands
    Block length now has same size on both connection sides
    in compressed file transfers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants