From 2b65a29b423f32f51210dc7ac871a723792ccd27 Mon Sep 17 00:00:00 2001 From: Jess Kube <44536565+jessk-msft@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:19:04 -0700 Subject: [PATCH] Fixing support for specifying a value for P4TICKETS from within a P4CONFIG file (#53) * adding test to fail P4TICKETS in P4CONFIG * fixing DepotClient P4TICKETS in P4CONFIG --- source/P4VFS.Console/P4VFS.Notes.txt | 6 ++++ source/P4VFS.Core/Include/DepotClient.h | 1 + source/P4VFS.Core/Source/DepotClient.cpp | 31 +++++++++++++++++++ source/P4VFS.Core/Source/FileSystem.cpp | 1 + source/P4VFS.Driver/Include/DriverVersion.h | 2 +- .../P4VFS.UnitTest/Source/UnitTestCommon.cs | 11 +++++++ 6 files changed, 51 insertions(+), 1 deletion(-) diff --git a/source/P4VFS.Console/P4VFS.Notes.txt b/source/P4VFS.Console/P4VFS.Notes.txt index 878c814..fcfea58 100644 --- a/source/P4VFS.Console/P4VFS.Notes.txt +++ b/source/P4VFS.Console/P4VFS.Notes.txt @@ -1,5 +1,11 @@ Microsoft P4VFS Release Notes +Version [1.28.2.0] +* Fixing support for specifying a value for P4TICKETS from within a P4CONFIG file, + and correctly used from working directory of p4vfs.exe, or placeholder file folder + during service hydration. Service requires P4CONFIG set in system environment or + system registry. + Version [1.28.1.0] * Fixing possible memory leak during sync operation while accumulating logging elements for statistics diff --git a/source/P4VFS.Core/Include/DepotClient.h b/source/P4VFS.Core/Include/DepotClient.h index 8525814..91c8cc3 100644 --- a/source/P4VFS.Core/Include/DepotClient.h +++ b/source/P4VFS.Core/Include/DepotClient.h @@ -53,6 +53,7 @@ namespace P4 { P4VFS_CORE_API DepotString GetTrustFilePath() const; P4VFS_CORE_API DepotString GetClientOwnerUserName(const DepotString& clientName, const DepotString& portName); P4VFS_CORE_API DepotString GetHostName() const; + P4VFS_CORE_API DepotString GetConfigEnv(const char* envVarName) const; P4VFS_CORE_API const DepotConfig& Config() const; P4VFS_CORE_API void Run(const DepotCommand& cmd, FDepotResult& result); diff --git a/source/P4VFS.Core/Source/DepotClient.cpp b/source/P4VFS.Core/Source/DepotClient.cpp index ef3b5d4..a0d8b4a 100644 --- a/source/P4VFS.Core/Source/DepotClient.cpp +++ b/source/P4VFS.Core/Source/DepotClient.cpp @@ -18,6 +18,7 @@ #include "p4/i18napi.h" #include "p4/charcvt.h" #include "p4/enviro.h" +#include "p4/strarray.h" #include "p4/debug.h" #pragma warning(pop) @@ -623,6 +624,16 @@ DepotString FDepotClient::GetTicketsFilePath() const } } + const DepotString configTicketsPath = GetConfigEnv(DepotConstants::P4TICKETS); + if (configTicketsPath.empty() == false) + { + const WString configTicketsPathW = StringInfo::ToWide(configTicketsPath); + if (FileInfo::CreateWritableFile(configTicketsPathW.c_str())) + { + return StringInfo::ToAnsi(FileInfo::FullPath(configTicketsPathW.c_str())); + } + } + const WString profileFolder = GetEnvImpersonatedW(DepotConstants::USERPROFILE); if (FileInfo::IsDirectory(profileFolder.c_str())) { @@ -769,6 +780,26 @@ DepotString FDepotClient::GetHostName() const return GetEnv(DepotConstants::COMPUTERNAME); } +DepotString FDepotClient::GetConfigEnv(const char* envVarName) const +{ + if (m_P4->m_ClientApi.get() != nullptr) + { + const StrArray* configFiles = m_P4->m_ClientApi->GetConfigs(); + if (configFiles != nullptr && configFiles->Count() > 0) + { + if (Enviro* apiEnv = m_P4->m_ClientApi->GetEnviro()) + { + const char* envVarValue = apiEnv->Get(envVarName); + if (StringInfo::IsNullOrEmpty(envVarValue) == false) + { + return DepotString(envVarValue); + } + } + } + } + return DepotString(); +} + bool FDepotClient::Login() { if (LoginUsingConfig()) diff --git a/source/P4VFS.Core/Source/FileSystem.cpp b/source/P4VFS.Core/Source/FileSystem.cpp index 6993235..4b2fc0b 100644 --- a/source/P4VFS.Core/Source/FileSystem.cpp +++ b/source/P4VFS.Core/Source/FileSystem.cpp @@ -200,6 +200,7 @@ ResolveFileResidency( config.m_Port = P4::DepotOperations::ResolveDepotServerName(StringInfo::ToAnsi(populateInfo->depotServer.c_str())); config.m_User = StringInfo::ToAnsi(populateInfo->depotUser.c_str()); config.m_Client = StringInfo::ToAnsi(populateInfo->depotClient.c_str()); + config.m_Directory = StringInfo::ToAnsi(FileInfo::FolderPath(filePath)); const P4::DepotConfig& configKey = config; // Make sure we go through all existing clients and a new one before giving up diff --git a/source/P4VFS.Driver/Include/DriverVersion.h b/source/P4VFS.Driver/Include/DriverVersion.h index 017af84..7a62b84 100644 --- a/source/P4VFS.Driver/Include/DriverVersion.h +++ b/source/P4VFS.Driver/Include/DriverVersion.h @@ -4,7 +4,7 @@ #define P4VFS_VER_MAJOR 1 // Increment this number almost never #define P4VFS_VER_MINOR 28 // Increment this number whenever the driver changes -#define P4VFS_VER_BUILD 1 // Increment this number when a major user mode change has been made +#define P4VFS_VER_BUILD 2 // Increment this number when a major user mode change has been made #define P4VFS_VER_REVISION 0 // Increment this number when we rebuild with any change #define P4VFS_VER_STRINGIZE_EX(v) L#v diff --git a/source/P4VFS.UnitTest/Source/UnitTestCommon.cs b/source/P4VFS.UnitTest/Source/UnitTestCommon.cs index 973625b..0c1baa3 100644 --- a/source/P4VFS.UnitTest/Source/UnitTestCommon.cs +++ b/source/P4VFS.UnitTest/Source/UnitTestCommon.cs @@ -1475,6 +1475,17 @@ public void EnvironmentConfigTest() Assert(depotClient.ConnectionClient().Client == "p4vfstest-depot"); Assert(depotClient.Info().UserName == "p4vfstest"); Assert(ProcessInfo.ExecuteWaitOutput(P4vfsExe, "info", directory:subFolder, echo:true, log:true).Lines.Contains("P4 UserName: p4vfstest")); + // Override P4TICKETS from P4CONFIG + string configTicketsFile = Path.Combine(subFolder, "tix.txt"); + AssertLambda(() => FileUtilities.DeleteFile(configTicketsFile)); + AssertLambda(() => File.WriteAllLines(Path.Combine(rootFolder, configFileName), configFileLines.Append($"P4TICKETS={configTicketsFile}").ToArray())); + Assert(depotClient.Connect(directoryPath:rootFolder) == false); + Assert(File.Exists(configTicketsFile) && FileUtilities.GetFileLength(configTicketsFile) == 0); + ProcessInfo.ExecuteResultOutput xr = ProcessInfo.ExecuteWaitOutput(P4Exe, "depots", directory:rootFolder, echo:true); + Assert(xr.ExitCode != 0 && xr.Data.Any(s => s.Text.Contains("Perforce password (P4PASSWD) invalid or unset."))); + Assert(depotClient.Connect(directoryPath:rootFolder, depotPasswd:UnitTestServer.GetUserP4Passwd(_P4User))); + Assert(depotClient.Depots().HasError == false); + Assert(File.Exists(configTicketsFile) && FileUtilities.GetFileLength(configTicketsFile) > 0); }} };