Skip to content

Commit

Permalink
Fixing support for specifying a value for P4TICKETS from within a P4C…
Browse files Browse the repository at this point in the history
…ONFIG file (#53)

* adding test to fail P4TICKETS in P4CONFIG

* fixing DepotClient P4TICKETS in P4CONFIG
  • Loading branch information
jessk-msft authored Oct 13, 2024
1 parent cc1a189 commit 2b65a29
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
6 changes: 6 additions & 0 deletions source/P4VFS.Console/P4VFS.Notes.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions source/P4VFS.Core/Include/DepotClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 31 additions & 0 deletions source/P4VFS.Core/Source/DepotClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()))
{
Expand Down Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions source/P4VFS.Core/Source/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/P4VFS.Driver/Include/DriverVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions source/P4VFS.UnitTest/Source/UnitTestCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}}
};

Expand Down

0 comments on commit 2b65a29

Please sign in to comment.