1 /*
2  * lftp - file transfer program
3  *
4  * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net)
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef GETFILEINFO_H
21 #define GETFILEINFO_H
22 
23 #include "trio.h"
24 
25 #include "SMTask.h"
26 #include "FileAccess.h"
27 
28 class GetFileInfo : public ListInfo
29 {
30    const FileAccessRef& session;
31 
32    SMTaskRef<ListInfo> li;
33 
34    /* file or dir we're listing: */
35    xstring_c dir;
36 
37    /* directory we've actually listed: */
38    xstring_c path_to_prefix;
39 
40    /* directory we started in: */
41    FileAccess::Path origdir;
42 
43    /* In showdir mode, we make sure the path actually exists; this is
44     * the filename to look for. */
45    xstring verify_fn;
46 
47    bool showdir;
48 
49    enum state_t { INITIAL, CHANGE_DIR, CHANGING_DIR, GETTING_LIST, GETTING_INFO_ARRAY, DONE } state;
50    /* whether we've tried to cd to the whole dir (treating it as a dir): */
51    bool tried_dir;
52    /* and whether we've tried to cd to the basename (treating it as a file): */
53    bool tried_file;
54    /* and the last-ditch GetInfoArray */
55    bool tried_info;
56    /* whether we found out the file type from cache */
57    bool from_cache;
58    /* whether the given path was a file or directory. */
59    bool was_directory;
60    /* if true, prepend the appropriate relative path to the result */
61    bool prepend_path;
62 
63    xstring_c saved_error_text;
64 
65    FileSet get_info;
66 
67    void PrepareToDie();
68 
69 public:
70    GetFileInfo(const FileAccessRef& a, const char *path, bool showdir);
71    virtual ~GetFileInfo();
72 
73    int Do();
74    const char *Status();
WasDirectory()75    bool WasDirectory() const { return was_directory; }
DontPrependPath()76    void DontPrependPath() { prepend_path=false; }
77 };
78 
79 #endif /* GETFILEINFO_H */
80