From 88f2abcdab72171cad7914dd9e4fcebdd4f0de12 Mon Sep 17 00:00:00 2001 From: Damian Suess Date: Mon, 2 May 2022 18:28:32 -0400 Subject: [PATCH] Fixed folder cleanup. Added more logging. Updated Output Window drop-down title to "Linux Debugger" from "Remote Debugger" --- src/VsLinuxDebugger/Commands.Impl.cs | 4 +-- src/VsLinuxDebugger/Core/LaunchBuilder.cs | 11 ++++---- src/VsLinuxDebugger/Core/RemoteDebugger.cs | 2 +- src/VsLinuxDebugger/Core/SshTool.cs | 32 ++++++++-------------- src/VsLinuxDebugger/Logger.cs | 5 +++- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/VsLinuxDebugger/Commands.Impl.cs b/src/VsLinuxDebugger/Commands.Impl.cs index 4017a71..2902b12 100644 --- a/src/VsLinuxDebugger/Commands.Impl.cs +++ b/src/VsLinuxDebugger/Commands.Impl.cs @@ -36,13 +36,13 @@ private async Task 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; } diff --git a/src/VsLinuxDebugger/Core/LaunchBuilder.cs b/src/VsLinuxDebugger/Core/LaunchBuilder.cs index fed3503..be9e248 100644 --- a/src/VsLinuxDebugger/Core/LaunchBuilder.cs +++ b/src/VsLinuxDebugger/Core/LaunchBuilder.cs @@ -55,11 +55,10 @@ public LaunchBuilder(DTE2 dte, Project dteProject, UserOptions o) public string ProjectName { get; set; } /// Full path to the remote assembly. (i.e. `/home/USER/VLSDbg/Proj/ConsoleApp1.dll`) - public string RemoteDeployAssemblyFilePath => LinuxPath.Combine(RemoteDeployFolder, $"{AssemblyName}.dll"); + public string RemoteDeployAssemblyFilePath => LinuxPath.Combine(RemoteDeployProjectFolder, $"{AssemblyName}.dll"); /// Folder of our remote assembly. (i.e. `/home/USER/VLSDbg/Proj`) - public string RemoteDeployFolder => - LinuxPath.Combine(_opts.RemoteDeployBasePath, ProjectName); + public string RemoteDeployProjectFolder => LinuxPath.Combine(_opts.RemoteDeployBasePath, ProjectName); public string RemoteDotNetPath => _opts.RemoteDotNetPath; @@ -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) { @@ -119,7 +118,7 @@ public string GenerateLaunchJson(bool vsdbgLogging = false) var obj = new Launch( RemoteDotNetPath, $"{AssemblyName}.dll", /// RemoteDeployAppPath, - RemoteDeployFolder, + RemoteDeployProjectFolder, default, false) { @@ -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; } diff --git a/src/VsLinuxDebugger/Core/RemoteDebugger.cs b/src/VsLinuxDebugger/Core/RemoteDebugger.cs index f701eb0..ac2ac00 100644 --- a/src/VsLinuxDebugger/Core/RemoteDebugger.cs +++ b/src/VsLinuxDebugger/Core/RemoteDebugger.cs @@ -62,7 +62,7 @@ public async Task BeginAsync(BuildOptions buildOptions) { if (!ssh.Connect()) { - Console.WriteLine("Could not connect to remote device."); + Logger.Output("Could not connect to remote device."); return false; } diff --git a/src/VsLinuxDebugger/Core/SshTool.cs b/src/VsLinuxDebugger/Core/SshTool.cs index ffdcdd0..4c973a2 100644 --- a/src/VsLinuxDebugger/Core/SshTool.cs +++ b/src/VsLinuxDebugger/Core/SshTool.cs @@ -51,22 +51,20 @@ public string Bash(string command) /// Cleans the contents of the deployment path. /// Clear entire base deployment folder (TRUE) or just our project. - 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}"); } } @@ -189,16 +187,16 @@ public async Task 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); @@ -299,12 +297,6 @@ private ConcurrentDictionary GetLocalFiles(DirectoryInfo srcDi return localFileCache; } - private void LogOutput(string message) - { - Console.WriteLine($">> {message}"); - Logger.Output(message); - } - /// Compress build contents and upload to remote host. /// SFTP connection. /// Build (source) contents directory info. @@ -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; } } @@ -416,7 +408,7 @@ private async Task 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}\""; diff --git a/src/VsLinuxDebugger/Logger.cs b/src/VsLinuxDebugger/Logger.cs index 3174eec..9562d3b 100644 --- a/src/VsLinuxDebugger/Logger.cs +++ b/src/VsLinuxDebugger/Logger.cs @@ -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;