Skip to content

Commit

Permalink
Fixed folder cleanup. Added more logging. Updated Output Window drop-…
Browse files Browse the repository at this point in the history
…down title to "Linux Debugger" from "Remote Debugger"
  • Loading branch information
DamianSuess committed May 2, 2022
1 parent 134d9e6 commit 88f2abc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/VsLinuxDebugger/Commands.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ private async Task<bool> ExecuteBuildAsync(BuildOptions buildOptions)

if (!dbg.IsProjectValid())
{
Console.WriteLine("No C# startup project/solution loaded.");
Logger.Output("No C# startup project/solution loaded.");
return false;
}

if (!await dbg.BeginAsync(buildOptions))
{
Console.WriteLine("Failed to perform actions.");
Logger.Output("Failed to perform actions.");
return false;
}

Expand Down
11 changes: 5 additions & 6 deletions src/VsLinuxDebugger/Core/LaunchBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ public LaunchBuilder(DTE2 dte, Project dteProject, UserOptions o)
public string ProjectName { get; set; }

/// <summary>Full path to the remote assembly. (i.e. `/home/USER/VLSDbg/Proj/ConsoleApp1.dll`)</summary>
public string RemoteDeployAssemblyFilePath => LinuxPath.Combine(RemoteDeployFolder, $"{AssemblyName}.dll");
public string RemoteDeployAssemblyFilePath => LinuxPath.Combine(RemoteDeployProjectFolder, $"{AssemblyName}.dll");

/// <summary>Folder of our remote assembly. (i.e. `/home/USER/VLSDbg/Proj`)</summary>
public string RemoteDeployFolder =>
LinuxPath.Combine(_opts.RemoteDeployBasePath, ProjectName);
public string RemoteDeployProjectFolder => LinuxPath.Combine(_opts.RemoteDeployBasePath, ProjectName);

public string RemoteDotNetPath => _opts.RemoteDotNetPath;

Expand Down Expand Up @@ -90,7 +89,7 @@ public string GenerateLaunchJson(bool vsdbgLogging = false)

var vsdbgLogPath = "";
if (vsdbgLogging)
vsdbgLogPath = $" --engineLogging={LinuxPath.Combine(RemoteDeployFolder, "_vsdbg.log")}";
vsdbgLogPath = $" --engineLogging={LinuxPath.Combine(RemoteDeployProjectFolder, "_vsdbg.log")}";

if (!_opts.LocalPlinkEnabled)
{
Expand Down Expand Up @@ -119,7 +118,7 @@ public string GenerateLaunchJson(bool vsdbgLogging = false)
var obj = new Launch(
RemoteDotNetPath,
$"{AssemblyName}.dll", /// RemoteDeployAppPath,
RemoteDeployFolder,
RemoteDeployProjectFolder,
default,
false)
{
Expand All @@ -142,7 +141,7 @@ public string GenerateLaunchJson(bool vsdbgLogging = false)
}
catch (Exception ex)
{
Console.WriteLine($"Error writing 'launch.json' to path, '{outputPath}'!\n{ex.Message}");
Logger.Output($"Error writing 'launch.json' to path, '{outputPath}'!\n{ex.Message}");
outputPath = string.Empty;
}

Expand Down
2 changes: 1 addition & 1 deletion src/VsLinuxDebugger/Core/RemoteDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<bool> BeginAsync(BuildOptions buildOptions)
{
if (!ssh.Connect())
{
Console.WriteLine("Could not connect to remote device.");
Logger.Output("Could not connect to remote device.");
return false;
}

Expand Down
32 changes: 12 additions & 20 deletions src/VsLinuxDebugger/Core/SshTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,20 @@ public string Bash(string command)

/// <summary>Cleans the contents of the deployment path.</summary>
/// <param name="fullScrub">Clear entire base deployment folder (TRUE) or just our project.</param>
public void CleanDeploymentFolder(bool fullScrub = true)
public void CleanDeploymentFolder(bool fullScrub = false)
{
//// Bash($"sudo rm -rf {_opts.RemoteDeployBasePath}/*");
// Whole deployment folder and hidden files
// rm -rf xxx/* == Contents of the folder but not the folder itself
// rm -rf xxx/{*,.*} == All hidden files and folders
var filesAndFolders = "{*,.*}";

if (fullScrub)
{
// Whole deployment folder and hidden files
// rm -rf xxx/* == Contents of the folder but not the folder itself
// rm -rf xxx/{*,.*} == All hidden files and folders
var filesAndFolders = "{*,.*}";
Bash($"rm -rf \"{_opts.RemoteDeployBasePath}/{filesAndFolders}\"");
}
else
{
// Full path to the file we'll execute (i.e. "/home/USER/VsLinuxDbg/PROJECT/AppName.dll").
Bash($"rm -rf \"{_launch.RemoteDeployAssemblyFilePath}\"");
Bash($"rm -rf {_launch.RemoteDeployProjectFolder}/{filesAndFolders}");
}
}

Expand Down Expand Up @@ -189,16 +187,16 @@ public async Task<string> UploadFilesAsync()
// TODO: Rev1 - Iterate through each file and upload it via SCP client or SFTP.
// TODO: Rev2 - Compress _localHost.OutputDirFullName, upload ZIP, and unzip it.
// TODO: Rev3 - Allow for both SFTP and SCP as a backup. This separating connection to a new disposable class.
//// LogOutput($"Connected to {_connectionInfo.Username}@{_connectionInfo.Host}:{_connectionInfo.Port} via SSH and {(_sftpClient != null ? "SFTP" : "SCP")}");
//// Logger.Output($"Connected to {_connectionInfo.Username}@{_connectionInfo.Host}:{_connectionInfo.Port} via SSH and {(_sftpClient != null ? "SFTP" : "SCP")}");

Bash($@"mkdir -p {_launch.RemoteDeployFolder}");
Bash($@"mkdir -p {_launch.RemoteDeployProjectFolder}");

var srcDirInfo = new DirectoryInfo(_launch.OutputDirFullPath);
if (!srcDirInfo.Exists)
throw new DirectoryNotFoundException($"Directory '{_launch.OutputDirFullPath}' not found!");

// Compress files to upload as single `tar.gz`.
var destTarGz = LinuxPath.Combine(_launch.RemoteDeployFolder, _tarGzFileName);
var destTarGz = LinuxPath.Combine(_launch.RemoteDeployProjectFolder, _tarGzFileName);
Logger.Output($"Destination Tar.GZ: '{destTarGz}'");

var success = await PayloadCompressAndUploadAsync(_sftp, srcDirInfo, destTarGz);
Expand Down Expand Up @@ -299,12 +297,6 @@ private ConcurrentDictionary<string, FileInfo> GetLocalFiles(DirectoryInfo srcDi
return localFileCache;
}

private void LogOutput(string message)
{
Console.WriteLine($">> {message}");
Logger.Output(message);
}

/// <summary>Compress build contents and upload to remote host.</summary>
/// <param name="sftp">SFTP connection.</param>
/// <param name="srcDirInfo">Build (source) contents directory info.</param>
Expand Down Expand Up @@ -391,12 +383,12 @@ await Task.Run(() =>
sftp.UploadFile(tarGzStream, pathBuildTarGz);
});

LogOutput($"Uploaded '{_tarGzFileName}' [{tarGzSize,13:n0} bytes].");
Logger.Output($"Uploaded '{_tarGzFileName}' [{tarGzSize,13:n0} bytes].");
success = true;
}
catch (Exception ex)
{
LogOutput($"Error while uploading file. {ex.Message}\n{ex.StackTrace}");
Logger.Output($"Error while uploading file. {ex.Message}\n{ex.StackTrace}");
success = false;
}
}
Expand All @@ -416,7 +408,7 @@ private async Task<bool> PayloadDecompressAsync(string pathBuildTarGz, bool remo
var decompressOutput = string.Empty;

var cmd = "set -e";
cmd += $";cd \"{_launch.RemoteDeployFolder}\"";
cmd += $";cd \"{_launch.RemoteDeployProjectFolder}\"";
cmd += $";tar -zxf \"{_tarGzFileName}\"";
////cmd += $";tar -zxf \"{pathBuildTarGz}\"";

Expand Down
5 changes: 4 additions & 1 deletion src/VsLinuxDebugger/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ private static string FormattedTime
}
}

public static void Init(IServiceProvider provider, OutputWindowType outputType = OutputWindowType.Debug, string name = "Remote Debugger")
public static void Init(
IServiceProvider provider,
OutputWindowType outputType = OutputWindowType.Debug,
string name = "Linux Debugger")
{
_provider = provider;
_outputType = outputType;
Expand Down

0 comments on commit 88f2abc

Please sign in to comment.