Skip to content

Commit

Permalink
Merge branch 'main' into far3-dev-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellukashov committed Apr 2, 2024
2 parents 85f722b + 088a48b commit 69daf45
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 66 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

### Fixes

Thanks to ssvine https://github.com/ssvine
* gh-437 SCP: don't hang if binary data is accidentally written to the terminal
* gh-435 Fix several tinylog problems
* gh-434 Prevent silent termination under certain conditions
* gh-433 Fix FTP crash on certain servers

### Fixes

Thanks to ssvine https://github.com/ssvine
* gh-435 Fix several tinylog problems
* gh-434 Prevent silent termination under certain conditions
Expand Down
4 changes: 2 additions & 2 deletions src/NetBox/FarPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,13 +849,13 @@ intptr_t TCustomFarPlugin::ProcessEditorInput(const struct ProcessEditorInputInf

int32_t TCustomFarPlugin::MaxMessageLines() const
{
return std::min<int32_t>(1, TerminalInfo().y - 5);
return std::max<int32_t>(1, TerminalInfo().y - 5);
}

int32_t TCustomFarPlugin::MaxMenuItemLength() const
{
// got from maximal length of path in FAR's folders history
return std::min<int32_t>(10, TerminalInfo().x - 13);
return std::max<int32_t>(10, TerminalInfo().x - 13);
}

int32_t TCustomFarPlugin::MaxLength(TStrings * Strings) const
Expand Down
2 changes: 2 additions & 0 deletions src/NetBox/WinSCPDialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5789,12 +5789,14 @@ bool TCopyDialog::Execute(UnicodeString & TargetDirectory,
base::UnixIncludeTrailingBackslash(TargetDirectory) :
::IncludeTrailingBackslash(TargetDirectory);
DEBUG_PRINTF("Directory: %s", Directory);
#if defined(__BORLANDC__)
if (FFileList->GetCount() == 1)
{
UnicodeString DestFileName = FFileList->GetString(0);
DestFileName = FToRemote ? DestFileName : FCopyParams.ChangeFileName(DestFileName, osRemote, true);
FileMask = base::ExtractFileName(DestFileName, false);
}
#endif // defined(__BORLANDC__)
DEBUG_PRINTF("FileMask: %s", FileMask);
DirectoryEdit->SetText(Directory + FileMask);
QueueCheck->SetChecked(Params->GetQueue());
Expand Down
57 changes: 41 additions & 16 deletions src/NetBox/WinSCPFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ void TWinSCPFileSystem::GetOpenPanelInfoEx(OPENPANELINFO_FLAGS & Flags,
}
else
{
CurDir = FSessionsFolder;
CurDir = ROOTDIRECTORY + FSessionsFolder;
AFormat = "netbox";
Flags = !OPIF_DISABLESORTGROUPS | !OPIF_DISABLEHIGHLIGHTING | OPIF_USEATTRHIGHLIGHTING |
OPIF_ADDDOTS | OPIF_SHOWPRESERVECASE | OPIF_SHORTCUT;
Expand Down Expand Up @@ -2085,6 +2085,18 @@ void TWinSCPFileSystem::ClearCaches()
FTerminal->ClearCaches();
}

void TWinSCPFileSystem::ClearConnectedState()
{
FPathHistory->Clear();
FLastPath.Clear();
FEditHistories.clear();
FMultipleEdits.clear();
FOriginalEditFile.Clear();
FLastEditFile.Clear();
FLastMultipleEditFile.Clear();
FLastEditorID = -1;
}

void TWinSCPFileSystem::OpenSessionInPutty()
{
DebugAssert(Connected());
Expand Down Expand Up @@ -2545,7 +2557,10 @@ int32_t TWinSCPFileSystem::GetFilesEx(TObjectList * PanelItems, bool Move,
FFileList.reset(CreateFileList(PanelItems, osRemote));
try__finally
{
Result = GetFilesRemote(PanelItems, Move, DestPath, OpMode);
if (FFileList->GetCount() > 0)
{
Result = GetFilesRemote(PanelItems, Move, DestPath, OpMode);
}
}
__finally
{
Expand All @@ -2559,8 +2574,12 @@ int32_t TWinSCPFileSystem::GetFilesEx(TObjectList * PanelItems, bool Move,
UnicodeString Prompt;
if (PanelItems->GetCount() == 1)
{
Prompt = FORMAT(GetMsg(NB_EXPORT_SESSION_PROMPT),
PanelItems->GetAs<TFarPanelItem>(0)->GetFileName());
auto FileName = PanelItems->GetAs<TFarPanelItem>(0)->GetFileName();
if (FileName == PARENTDIRECTORY)
{
return Result;
}
Prompt = FORMAT(GetMsg(NB_EXPORT_SESSION_PROMPT), FileName);
}
else
{
Expand Down Expand Up @@ -2779,7 +2798,7 @@ int32_t TWinSCPFileSystem::UploadFiles(bool Move, OPERATION_MODES OpMode, bool E

int32_t TWinSCPFileSystem::PutFilesEx(TObjectList * PanelItems, bool Move, OPERATION_MODES OpMode)
{
int32_t Result;
int32_t Result = -1;
if (Connected())
{
FFileList.reset(CreateFileList(PanelItems, osLocal));
Expand All @@ -2788,6 +2807,10 @@ int32_t TWinSCPFileSystem::PutFilesEx(TObjectList * PanelItems, bool Move, OPERA
FPanelItems = nullptr;
FFileList.reset();
};
if (FFileList->GetCount() == 0)
{
return Result;
}
FPanelItems = PanelItems;

// if file is saved under different name, FAR tries to upload original file,
Expand Down Expand Up @@ -2828,21 +2851,18 @@ int32_t TWinSCPFileSystem::PutFilesEx(TObjectList * PanelItems, bool Move, OPERA
FTerminal->SetCurrentDirectory(CurrentDirectory);
}
}
else if (IsSessionList())
else if (IsSessionList() && PanelItems)
{
if (!ImportSessions(PanelItems, Move, OpMode))
if (PanelItems->GetCount() == 1 &&
PanelItems->GetAs<TFarPanelItem>(0)->GetFileName() == PARENTDIRECTORY)
{
Result = -1;
return Result;
}
else
if (ImportSessions(PanelItems, Move, OpMode))
{
Result = 1;
}
}
else
{
Result = -1;
}
return Result;
}

Expand Down Expand Up @@ -3108,6 +3128,7 @@ void TWinSCPFileSystem::Disconnect()
GetSessionData()->SetSynchronizeBrowsing(FSynchronisingBrowse);
}
SAFE_DESTROY(FTerminal);
ClearConnectedState();
}

void TWinSCPFileSystem::ConnectTerminal(TTerminal * Terminal)
Expand Down Expand Up @@ -4203,7 +4224,7 @@ void TWinSCPFileSystem::MultipleEdit(const UnicodeString & Directory,
else
{
UnicodeString TempDir;
TGUICopyParamType &CopyParam = GetGUIConfiguration()->GetDefaultCopyParam();
TGUICopyParamType CopyParam(GetGUIConfiguration()->GetDefaultCopyParam());
EditViewCopyParam(CopyParam);

std::unique_ptr<TStrings> FileList(std::make_unique<TStringList>());
Expand Down Expand Up @@ -4264,9 +4285,13 @@ void TWinSCPFileSystem::EditHistory()
const UnicodeString FullFileName =
TUnixPath::Join(EditHistory.Directory, EditHistory.FileName);
TRemoteFile * File = FTerminal->ReadFile(FullFileName);
if (File == nullptr)
{
// File is deleted, moved, etc
return;
}
std::unique_ptr<TRemoteFile> FilePtr(File);
DebugAssert(FilePtr.get());
if (File && !File->GetHaveFullFileName())
if (!File->GetHaveFullFileName())
{
File->SetFullFileName(FullFileName);
}
Expand Down
1 change: 1 addition & 0 deletions src/NetBox/WinSCPFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class TWinSCPFileSystem final : public TCustomFarFileSystem
void RequireLocalPanel(const TFarPanelInfo * Panel, const UnicodeString & Message);
bool AreCachesEmpty() const;
void ClearCaches();
void ClearConnectedState();
void OpenSessionInPutty();
void QueueShow(bool ClosingPlugin);
TTerminalQueueStatus * ProcessQueue(bool Hidden);
Expand Down
7 changes: 6 additions & 1 deletion src/NetBox/WinSCPPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,16 @@ TCustomFarFileSystem * TWinSCPPlugin::OpenPluginEx(OPENFROM OpenFrom, intptr_t I
// DEBUG_PRINTF("Directory: %s", Directory);
// DEBUG_PRINTF("CommandLine: %s", CommandLine);

UnicodeString SessionName(CommandLine);
if (SessionName.SubString(1, 7).LowerCase() == L"netbox:")
{
SessionName.Delete(1, 7);
}
const bool Another = !(Flags & FOSF_ACTIVE);
TWinSCPFileSystem * PanelSystem = rtti::dyn_cast_or_null<TWinSCPFileSystem>(GetPanelFileSystem());

if (PanelSystem && PanelSystem->Connected() &&
PanelSystem->GetTerminal()->GetSessionData()->GenerateSessionUrl(sufComplete) == CommandLine)
PanelSystem->GetTerminal()->GetSessionData()->GetSessionName() == SessionName)
{
PanelSystem->SetDirectoryEx(Directory, OPM_SILENT);
if (PanelSystem->UpdatePanel(false, Another))
Expand Down
18 changes: 6 additions & 12 deletions src/base/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,7 @@ UnicodeString ValidLocalFileName(
}
}

#if defined(__BORLANDC__)
// Windows trim trailing space or dot, hence we must encode it to preserve it
if (!FileName.IsEmpty() &&
((FileName[FileName.Length()] == L' ') ||
Expand All @@ -1381,6 +1382,7 @@ UnicodeString ValidLocalFileName(
}
FileName.Insert(L"%00", P);
}
#endif // defined(__BORLANDC__)
}
return FileName;
}
Expand Down Expand Up @@ -1941,25 +1943,17 @@ UnicodeString MakeUnicodeLargePath(const UnicodeString & APath)

UnicodeString ApiPath(const UnicodeString & APath)
{
UnicodeString Path = APath;
// Convert "/" to "\" as we're returning NT-style path
UnicodeString Path = base::FromUnixPath(APath);

const UnicodeString Drive = ExtractFileDrive(Path);
// This may match even a path like "C:" or "\\server\\share", but we do not really care
if (Drive.IsEmpty() || (Path.SubString(Drive.Length() + 1, 1) != BACKSLASH))
{
Path = ExpandFileName(Path);
}

// Max path for directories is 12 characters shorter than max path for files
if (Path.Length() >= (MAX_PATH - 12))
{
/*if (GetConfiguration() != nullptr)
{
GetConfiguration()->Usage->Inc(L"LongPath");
}*/
Path = MakeUnicodeLargePath(Path);
}
return Path;
// Return NT-style path unconditionally
return MakeUnicodeLargePath(Path);
}

UnicodeString DisplayableStr(const RawByteString & Str)
Expand Down
2 changes: 1 addition & 1 deletion src/core/CopyParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void TCopyParamType::Default()
SetInvalidCharsReplacement(TokenReplacement);
SetLocalInvalidChars(::LocalInvalidChars);
SetCalculateSize(true);
SetFileMask(AnyMask);
SetFileMask(L"");
GetIncludeFileMask().Masks("");
SetTransferSkipList(nullptr);
SetTransferResumeFile("");
Expand Down
23 changes: 12 additions & 11 deletions src/core/FtpFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,18 +621,19 @@ void TFTPFileSystem::Close()
DebugAssert(FActive);

bool Result = DoQuit();
if (Result)
return;
bool Opening = (FTerminal->GetStatus() == ssOpening);
if (FFileZillaIntf->Close(Opening))
{
DebugCheck(FLAGSET(WaitForCommandReply(false), TFileZillaIntf::REPLY_DISCONNECTED));
Result = true;
}
else
if (!Result)
{
// See TFileZillaIntf::Close
Result = Opening;
bool Opening = (FTerminal->GetStatus() == ssOpening);
if (FFileZillaIntf->Close(Opening))
{
DebugCheck(FLAGSET(WaitForCommandReply(false), TFileZillaIntf::REPLY_DISCONNECTED));
Result = true;
}
else
{
// See TFileZillaIntf::Close
Result = Opening;
}
}

if (DebugAlwaysTrue(Result))
Expand Down
6 changes: 3 additions & 3 deletions src/core/S3FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,8 @@ void TS3FileSystem::DoStartup()
// Capabilities of S3 protocol are fixed
FTerminal->SaveCapabilities(FFileSystemInfo);
FTerminal->SetExceptionOnFail(true);
// retrieve initialize working directory to save it as home directory
ReadCurrentDirectory();
// ReadCurrentDirectory is called later as the result of setting
// FReadCurrentDirectoryPending in TTerminal::DoStartup
FTerminal->SetExceptionOnFail(false);
}

Expand All @@ -1045,7 +1045,7 @@ void TS3FileSystem::ReadCurrentDirectory()
{
if (FCachedDirectoryChange.IsEmpty())
{
// FCurrentDirectory is set later during TTerminal::DoStartup execution
FCurrentDirectory = FCurrentDirectory.IsEmpty() ? UnicodeString(L"/") : FCurrentDirectory;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/core/SftpFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4828,6 +4828,7 @@ void TSFTPFileSystem::Source(
FTerminal->LogEvent("Checking existence of partially transferred file.");
if (RemoteFileExists(DestPartialFullName, &File))
{
FilePtr.reset(File);
ResumeOffset = FilePtr->Resolve()->GetSize(); // Though partial file should not be symlink
#if defined(__BORLANDC__)
delete File;
Expand Down
6 changes: 3 additions & 3 deletions src/core/WebDAVFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,8 @@ UnicodeString TWebDAVFileSystem::GetCurrentDirectory() const
void TWebDAVFileSystem::DoStartup()
{
FTerminal->SetExceptionOnFail(true);
// retrieve initialize working directory to save it as home directory
ReadCurrentDirectory();
// ReadCurrentDirectory is called later as the result of setting
// FReadCurrentDirectoryPending in TTerminal::DoStartup
FTerminal->SetExceptionOnFail(false);
}

Expand Down Expand Up @@ -738,7 +738,7 @@ void TWebDAVFileSystem::ReadCurrentDirectory()
{
if (FCachedDirectoryChange.IsEmpty())
{
// FCurrentDirectory is set later during TTerminal::DoStartup execution
FCurrentDirectory = FCurrentDirectory.IsEmpty() ? UnicodeString(ROOTDIRECTORY) : FCurrentDirectory;
}
else
{
Expand Down

0 comments on commit 69daf45

Please sign in to comment.