From 0ead378c8a19d4c7b86e35265a7f6e878fd63c0d Mon Sep 17 00:00:00 2001
From: "Alexander V. Lukyanov" <lavv17f@gmail.com>
Date: Wed, 20 Apr 2022 23:32:37 +0300
Subject: [PATCH] fill verify_fn in case of cd error; fix #650

---
 src/GetFileInfo.cc | 30 +++++++++++++++++++-----------
 src/GetFileInfo.h  |  2 ++
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/GetFileInfo.cc b/src/GetFileInfo.cc
index 7afb3d8f..b553544c 100644
--- a/src/GetFileInfo.cc
+++ b/src/GetFileInfo.cc
@@ -114,6 +114,22 @@ void GetFileInfo::PrepareToDie()
    }
 }
 
+void GetFileInfo::MakeVerifyFileName()
+{
+   /* Here we should have the home directory path. Find out
+    * the real name of the path.  (We may have something like "~/..".) */
+
+   FileAccess::Path pwd(session->GetCwd());
+
+   session->SetCwd(origdir);
+   session->Chdir(dir, false);
+
+   verify_fn.set(basename_ptr(session->GetCwd()));
+
+   /* go back */
+   session->SetCwd(pwd);
+}
+
 int GetFileInfo::Do()
 {
    int res;
@@ -241,6 +257,8 @@ int GetFileInfo::Do()
 	 if(!saved_error_text)
 	    saved_error_text.set(session->StrError(res));
 	 session->Close();
+         if(!verify_fn)
+            MakeVerifyFileName();
 	 if(res==FA::NO_FILE)
 	 {
 	    /* If this is a CWD to the parent, and it failed, we
@@ -262,17 +280,7 @@ int GetFileInfo::Do()
       /* Now that we've connected, we should have the home directory path. Find out
        * the real name of the path.  (We may have something like "~/..".) */
       if(!verify_fn)
-      {
-	 FileAccess::Path pwd(session->GetCwd());
-
-	 session->SetCwd(origdir);
-	 session->Chdir(dir, false);
-
-	 verify_fn.set(basename_ptr(session->GetCwd()));
-
-	 /* go back */
-	 session->SetCwd(pwd);
-      }
+         MakeVerifyFileName();
 
       /* Special case: looking up "/". Make a phony entry. */
       if(showdir && !strcmp(verify_fn, "/"))
diff --git a/src/GetFileInfo.h b/src/GetFileInfo.h
index 1ac8f4d2..483dcc33 100644
--- a/src/GetFileInfo.h
+++ b/src/GetFileInfo.h
@@ -66,6 +66,8 @@ class GetFileInfo : public ListInfo
 
    void PrepareToDie();
 
+   void MakeVerifyFileName();
+
 public:
    GetFileInfo(const FileAccessRef& a, const char *path, bool showdir);
    virtual ~GetFileInfo();
-- 
2.15.1.windows.2

