chdir back to the starting working directory
| 3037 | |
| 3038 | // chdir back to the starting working directory |
| 3039 | void Query::unselect() |
| 3040 | { |
| 3041 | if (!wdir_.empty()) |
| 3042 | { |
| 3043 | if (chdir(wdir_.c_str()) < 0) |
| 3044 | return; |
| 3045 | |
| 3046 | // a directory change affects --hyperlink |
| 3047 | set_terminal_hyperlink(); |
| 3048 | } |
| 3049 | else if (!dirs_.empty()) |
| 3050 | { |
| 3051 | if (!selected_file_.empty()) |
| 3052 | { |
| 3053 | size_t n = dirs_.find_last_of(PATHSEPCHR); |
| 3054 | |
| 3055 | if (n != std::string::npos) |
| 3056 | dirs_.resize(n + 1); |
| 3057 | else |
| 3058 | dirs_.clear(); |
| 3059 | } |
| 3060 | |
| 3061 | if (!dirs_.empty()) |
| 3062 | { |
| 3063 | while (true) |
| 3064 | { |
| 3065 | #ifdef OS_WIN |
| 3066 | if (dirs_.size() == 3 && dirs_.at(1) == ':' && dirs_.at(2) == PATHSEPCHR) |
| 3067 | break; |
| 3068 | #else |
| 3069 | if (dirs_ == PATHSEPSTR) |
| 3070 | break; |
| 3071 | #endif |
| 3072 | |
| 3073 | if (chdir("..") < 0) |
| 3074 | break; |
| 3075 | |
| 3076 | dirs_.pop_back(); |
| 3077 | |
| 3078 | size_t n = dirs_.find_last_of(PATHSEPCHR); |
| 3079 | |
| 3080 | if (n == std::string::npos) |
| 3081 | break; |
| 3082 | |
| 3083 | dirs_.resize(n + 1); |
| 3084 | } |
| 3085 | |
| 3086 | // a directory change affects --hyperlink |
| 3087 | set_terminal_hyperlink(); |
| 3088 | } |
| 3089 | } |
| 3090 | |
| 3091 | dirs_.clear(); |
| 3092 | wdir_.clear(); |
| 3093 | deselect_file_ = true; |
| 3094 | Static::arg_files.clear(); |
| 3095 | |
| 3096 | mark_.reset(); |