Skip to content

Commit

Permalink
Make FScopeTempFile use an absolute file path
Browse files Browse the repository at this point in the history
Fix new branch operations failing when using an Engine source build
  • Loading branch information
SRombautsU committed Jan 8, 2024
1 parent 7fd8de3 commit c660c20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ bool DeleteChangelist(const FPlasticSourceControlProvider& PlasticSourceControlP
{
Parameters.Add(TEXT("delete"));
const FScopedTempFile ChangelistNameFile(InChangelist.GetName());
Parameters.Add(FString::Printf(TEXT("--namefile=\"%s\""), *FPaths::ConvertRelativePathToFull(ChangelistNameFile.GetFilename())));
Parameters.Add(FString::Printf(TEXT("--namefile=\"%s\""), *ChangelistNameFile.GetFilename()));
UE_LOG(LogSourceControl, Verbose, TEXT("DeleteChangelist(%s)"), *InChangelist.GetName());
return PlasticSourceControlUtils::RunCommand(TEXT("changelist"), Parameters, Files, OutResults, OutErrorMessages);
}
Expand Down Expand Up @@ -454,7 +454,7 @@ bool FPlasticCheckInWorker::Execute(FPlasticSourceControlCommand& InCommand)
if (!CommitMsgFile.GetFilename().IsEmpty())
{
TArray<FString> Parameters;
Parameters.Add(FString::Printf(TEXT("--commentsfile=\"%s\""), *FPaths::ConvertRelativePathToFull(CommitMsgFile.GetFilename())));
Parameters.Add(FString::Printf(TEXT("--commentsfile=\"%s\""), *CommitMsgFile.GetFilename()));
if (!GetProvider().IsPartialWorkspace())
{
Parameters.Add(TEXT("--all")); // Also files Changed (not CheckedOut) and Moved/Deleted Locally
Expand Down Expand Up @@ -1703,9 +1703,9 @@ FPlasticSourceControlChangelist CreatePendingChangelist(FPlasticSourceControlPro
{
Parameters.Add(TEXT("create"));
const FScopedTempFile ChangelistNameFile(NewChangelist.GetName());
Parameters.Add(FString::Printf(TEXT("--namefile=\"%s\""), *FPaths::ConvertRelativePathToFull(ChangelistNameFile.GetFilename())));
Parameters.Add(FString::Printf(TEXT("--namefile=\"%s\""), *ChangelistNameFile.GetFilename()));
const FScopedTempFile ChangelistDescriptionFile(InDescription);
Parameters.Add(FString::Printf(TEXT("--descriptionfile=\"%s\""), *FPaths::ConvertRelativePathToFull(ChangelistDescriptionFile.GetFilename())));
Parameters.Add(FString::Printf(TEXT("--descriptionfile=\"%s\""), *ChangelistDescriptionFile.GetFilename()));
Parameters.Add(TEXT("--persistent")); // Create a persistent changelist to stay close to Perforce behavior
UE_LOG(LogSourceControl, Verbose, TEXT("CreatePendingChangelist(%s):\n\"%s\""), *NewChangelist.GetName(), *InDescription);
bCommandSuccessful = PlasticSourceControlUtils::RunCommand(TEXT("changelist"), Parameters, TArray<FString>(), InInfoMessages, InErrorMessages);
Expand All @@ -1732,10 +1732,10 @@ bool EditChangelistDescription(const FPlasticSourceControlProvider& PlasticSourc
else
{
const FScopedTempFile ChangelistNameFile(InChangelist.GetName());
Parameters.Add(FString::Printf(TEXT("--namefile=\"%s\""), *FPaths::ConvertRelativePathToFull(ChangelistNameFile.GetFilename())));
Parameters.Add(FString::Printf(TEXT("--namefile=\"%s\""), *ChangelistNameFile.GetFilename()));
Parameters.Add(TEXT("description"));
const FScopedTempFile ChangelistDescriptionFile(InDescription);
Parameters.Add(FString::Printf(TEXT("--descriptionfile=\"%s\""), *FPaths::ConvertRelativePathToFull(ChangelistDescriptionFile.GetFilename())));
Parameters.Add(FString::Printf(TEXT("--descriptionfile=\"%s\""), *ChangelistDescriptionFile.GetFilename()));
UE_LOG(LogSourceControl, Verbose, TEXT("EditChangelistDescription(%s\n%s)"), *InChangelist.GetName(), *InDescription);
return PlasticSourceControlUtils::RunCommand(TEXT("changelist"), Parameters, TArray<FString>(), InInfoMessages, InErrorMessages);
}
Expand All @@ -1755,7 +1755,7 @@ bool MoveFilesToChangelist(const FPlasticSourceControlProvider& PlasticSourceCon
else
{
const FScopedTempFile ChangelistNameFile(InChangelist.GetName());
Parameters.Add(FString::Printf(TEXT("--namefile=\"%s\""), *FPaths::ConvertRelativePathToFull(ChangelistNameFile.GetFilename())));
Parameters.Add(FString::Printf(TEXT("--namefile=\"%s\""), *ChangelistNameFile.GetFilename()));
Parameters.Add(TEXT("add"));
UE_LOG(LogSourceControl, Verbose, TEXT("MoveFilesToChangelist(%s)"), *InChangelist.GetName());
return PlasticSourceControlUtils::RunCommand(TEXT("changelist"), Parameters, InFiles, OutResults, OutErrorMessages);
Expand Down Expand Up @@ -2056,7 +2056,7 @@ bool CreateShelve(const FString& InChangelistName, const FString& InChangelistDe
const FString ShelveDescription = FString::Printf(TEXT("Changelist%s: %s"), *InChangelistName, *InChangelistDescription);
const FScopedTempFile CommentsFile(ShelveDescription);
Parameters.Add(TEXT("create"));
Parameters.Add(FString::Printf(TEXT("-commentsfile=\"%s\""), *FPaths::ConvertRelativePathToFull(CommentsFile.GetFilename())));
Parameters.Add(FString::Printf(TEXT("-commentsfile=\"%s\""), *CommentsFile.GetFilename()));
const bool bCommandSuccessful = PlasticSourceControlUtils::RunCommand(TEXT("shelveset"), Parameters, InFilesToShelve, Results, OutErrorMessages);
if (bCommandSuccessful && Results.Num() > 0)
{
Expand Down
20 changes: 10 additions & 10 deletions Source/PlasticSourceControl/Private/PlasticSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,9 @@ bool RunUpdate(const TArray<FString>& InFiles, const bool bInIsPartialWorkspace,
// Detect special case for a partial checkout (CS:-1 in Gluon mode)!
if (!bInIsPartialWorkspace)
{
const FScopedTempFile TempFile;
const FScopedTempFile UpdateResultFile;
TArray<FString> InfoMessages;
Parameters.Add(FString::Printf(TEXT("--xml=\"%s\""), *TempFile.GetFilename()));
Parameters.Add(FString::Printf(TEXT("--xml=\"%s\""), *UpdateResultFile.GetFilename()));
Parameters.Add(TEXT("--encoding=\"utf-8\""));
Parameters.Add(TEXT("--last"));
Parameters.Add(TEXT("--dontmerge"));
Expand All @@ -769,7 +769,7 @@ bool RunUpdate(const TArray<FString>& InFiles, const bool bInIsPartialWorkspace,
{
// Load and parse the result of the update command
FString Results;
if (FFileHelper::LoadFileToString(Results, *TempFile.GetFilename()))
if (FFileHelper::LoadFileToString(Results, *UpdateResultFile.GetFilename()))
{
bResult = PlasticSourceControlParsers::ParseUpdateResults(Results, OutUpdatedFiles);
}
Expand Down Expand Up @@ -1004,18 +1004,18 @@ bool RunSwitchToBranch(const FString& InBranchName, TArray<FString>& OutUpdatedF
{
bool bResult = false;

const FScopedTempFile TempFile;
const FScopedTempFile SwitchResultFile;
TArray<FString> InfoMessages;
TArray<FString> Parameters;
Parameters.Add(FString::Printf(TEXT("--xml=\"%s\""), *TempFile.GetFilename()));
Parameters.Add(FString::Printf(TEXT("--xml=\"%s\""), *SwitchResultFile.GetFilename()));
Parameters.Add(TEXT("--encoding=\"utf-8\""));
Parameters.Add(FString::Printf(TEXT("\"br:%s\""), *InBranchName));
bResult = PlasticSourceControlUtils::RunCommand(TEXT("switch"), Parameters, TArray<FString>(), InfoMessages, OutErrorMessages);
if (bResult)
{
// Load and parse the result of the update command
FString Results;
if (FFileHelper::LoadFileToString(Results, *TempFile.GetFilename()))
if (FFileHelper::LoadFileToString(Results, *SwitchResultFile.GetFilename()))
{
bResult = PlasticSourceControlParsers::ParseUpdateResults(Results, OutUpdatedFiles);
}
Expand All @@ -1028,10 +1028,10 @@ bool RunMergeBranch(const FString& InBranchName, TArray<FString>& OutUpdatedFile
{
bool bResult = false;

const FScopedTempFile TempFile;
const FScopedTempFile MergeResultFile;
TArray<FString> InfoMessages;
TArray<FString> Parameters;
Parameters.Add(FString::Printf(TEXT("--xml=\"%s\""), *TempFile.GetFilename()));
Parameters.Add(FString::Printf(TEXT("--xml=\"%s\""), *MergeResultFile.GetFilename()));
Parameters.Add(TEXT("--encoding=\"utf-8\""));
Parameters.Add(TEXT("--merge"));
Parameters.Add(FString::Printf(TEXT("\"br:%s\""), *InBranchName));
Expand All @@ -1040,7 +1040,7 @@ bool RunMergeBranch(const FString& InBranchName, TArray<FString>& OutUpdatedFile
{
// Load and parse the result of the update command
FString Results;
if (FFileHelper::LoadFileToString(Results, *TempFile.GetFilename()))
if (FFileHelper::LoadFileToString(Results, *MergeResultFile.GetFilename()))
{
PlasticSourceControlParsers::ParseMergeResults(Results, OutUpdatedFiles);
}
Expand All @@ -1059,7 +1059,7 @@ bool RunCreateBranch(const FString& InBranchName, const FString& InComment, TArr
TArray<FString> InfoMessages;
Parameters.Add(TEXT("create"));
Parameters.Add(FString::Printf(TEXT("\"%s\""), *InBranchName));
Parameters.Add(FString::Printf(TEXT("--commentsfile=\"%s\""), *FPaths::ConvertRelativePathToFull(BranchCommentFile.GetFilename())));
Parameters.Add(FString::Printf(TEXT("--commentsfile=\"%s\""), *BranchCommentFile.GetFilename()));
return PlasticSourceControlUtils::RunCommand(TEXT("branch"), Parameters, TArray<FString>(), InfoMessages, OutErrorMessages);
}

Expand Down
6 changes: 3 additions & 3 deletions Source/PlasticSourceControl/Private/ScopedTempFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

FScopedTempFile::FScopedTempFile()
{
Filename = FPaths::CreateTempFilename(*FPaths::ProjectLogDir(), TEXT("Plastic-Temp"), TEXT(".txt"));
Filename = FPaths::CreateTempFilename(*FPaths::ConvertRelativePathToFull(FPaths::ProjectLogDir()), TEXT("Plastic-Temp"), TEXT(".xml"));
}

FScopedTempFile::FScopedTempFile(const FString& InText)
{
Filename = FPaths::CreateTempFilename(*FPaths::ProjectLogDir(), TEXT("Plastic-Temp"), TEXT(".txt"));
Filename = FPaths::CreateTempFilename(*FPaths::ConvertRelativePathToFull(FPaths::ProjectLogDir()), TEXT("Plastic-Temp"), TEXT(".txt"));
if (!FFileHelper::SaveStringToFile(InText, *Filename, FFileHelper::EEncodingOptions::ForceUTF8WithoutBOM))
{
UE_LOG(LogSourceControl, Error, TEXT("Failed to write to temp file: %s"), *Filename);
Expand All @@ -24,7 +24,7 @@ FScopedTempFile::FScopedTempFile(const FString& InText)

FScopedTempFile::FScopedTempFile(const FText& InText)
{
Filename = FPaths::CreateTempFilename(*FPaths::ProjectLogDir(), TEXT("Plastic-Temp"), TEXT(".txt"));
Filename = FPaths::CreateTempFilename(*FPaths::ConvertRelativePathToFull(FPaths::ProjectLogDir()), TEXT("Plastic-Temp"), TEXT(".txt"));
if (!FFileHelper::SaveStringToFile(InText.ToString(), *Filename, FFileHelper::EEncodingOptions::ForceUTF8WithoutBOM))
{
UE_LOG(LogSourceControl, Error, TEXT("Failed to write to temp file: %s"), *Filename);
Expand Down

0 comments on commit c660c20

Please sign in to comment.