|
Packit |
8f70b4 |
/*
|
|
Packit |
8f70b4 |
* lftp - file transfer program
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net)
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
8f70b4 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
8f70b4 |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit |
8f70b4 |
* (at your option) any later version.
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
8f70b4 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8f70b4 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
8f70b4 |
* GNU General Public License for more details.
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
8f70b4 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
8f70b4 |
*/
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#ifndef FINDJOB_H
|
|
Packit |
8f70b4 |
#define FINDJOB_H
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#include "Job.h"
|
|
Packit |
8f70b4 |
#include "buffer.h"
|
|
Packit |
8f70b4 |
#include "ArgV.h"
|
|
Packit |
8f70b4 |
#include "GetFileInfo.h"
|
|
Packit |
8f70b4 |
#include "PatternSet.h"
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class FinderJob : public SessionJob
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
FileAccessRef my_session;
|
|
Packit |
8f70b4 |
FileAccess::Path orig_init_dir;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
xstring_c dir;
|
|
Packit |
8f70b4 |
int errors;
|
|
Packit |
8f70b4 |
SMTaskRef<GetFileInfo> li;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class place
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
friend class FinderJob;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
xstring_c path;
|
|
Packit |
8f70b4 |
Ref<FileSet> fset;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
place(const char *p,FileSet *f) : path(p), fset(f) {}
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
RefArray<place> stack;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void Up();
|
|
Packit |
8f70b4 |
void Down(const char *d);
|
|
Packit |
8f70b4 |
void Push(FileSet *f);
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
virtual void Enter(const char *d) { }
|
|
Packit |
8f70b4 |
virtual void Exit() { }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
bool depth_done;
|
|
Packit |
8f70b4 |
unsigned file_info_need;
|
|
Packit |
8f70b4 |
/* In certain circumstances, we can skip a LIST altogether and just
|
|
Packit |
8f70b4 |
* pass argument names on: we don't need anything other than the name
|
|
Packit |
8f70b4 |
* (no other file_info_needs) and we're not recursing (which would imply
|
|
Packit |
8f70b4 |
* needing the type.) This means arguments that don't actually exist
|
|
Packit |
8f70b4 |
* get passed on; if this is inappropriate (ie for a simple Find),
|
|
Packit |
8f70b4 |
* call ValidateArgs(). */
|
|
Packit |
8f70b4 |
bool validate_args;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
Ref<PatternSet> exclude;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
protected:
|
|
Packit |
8f70b4 |
enum state_t { START_INFO, INFO, LOOP, PROCESSING, WAIT, DONE };
|
|
Packit |
8f70b4 |
state_t state;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
const char *op;
|
|
Packit |
8f70b4 |
FileAccessRefC session;
|
|
Packit |
8f70b4 |
FileAccess::Path init_dir;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
enum prf_res { PRF_FATAL, PRF_ERR, PRF_OK, PRF_WAIT, PRF_LATER };
|
|
Packit |
8f70b4 |
virtual prf_res ProcessFile(const char *d,const FileInfo *fi);
|
|
Packit |
8f70b4 |
virtual void ProcessList(FileSet *f) { }
|
|
Packit |
8f70b4 |
virtual void Finish() {};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
bool show_sl;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
bool depth_first;
|
|
Packit |
8f70b4 |
bool use_cache;
|
|
Packit |
8f70b4 |
bool quiet;
|
|
Packit |
8f70b4 |
int maxdepth;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void NextDir(const char *d);
|
|
Packit |
8f70b4 |
const char *GetCur() const { return dir; }
|
|
Packit |
8f70b4 |
void Need(unsigned need) { file_info_need=need; }
|
|
Packit |
8f70b4 |
void ValidateArgs() { validate_args=true; }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
bool ProcessingURL() { return session!=SessionJob::session; }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
int Do();
|
|
Packit |
8f70b4 |
int Done() { return state==DONE; }
|
|
Packit |
8f70b4 |
int ExitCode() { return state!=DONE || (errors && !quiet); }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void Init();
|
|
Packit |
8f70b4 |
FinderJob(FileAccess *s);
|
|
Packit |
8f70b4 |
void PrepareToDie() { session->Close(); SessionJob::PrepareToDie(); }
|
|
Packit |
8f70b4 |
~FinderJob();
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void ShowRunStatus(const SMTaskRef<StatusLine>&);
|
|
Packit |
8f70b4 |
xstring& FormatStatus(xstring&,int,const char *);
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void BeQuiet() { quiet=true; }
|
|
Packit |
8f70b4 |
void SetExclude(PatternSet *p) { exclude = p; }
|
|
Packit |
8f70b4 |
void set_maxdepth(int _maxdepth) { maxdepth = _maxdepth; }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void Fg();
|
|
Packit |
8f70b4 |
void Bg();
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class FinderJob_List : public FinderJob
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
SMTaskRef<IOBuffer> buf;
|
|
Packit |
8f70b4 |
Ref<ArgV> args;
|
|
Packit |
8f70b4 |
bool long_listing;
|
|
Packit |
8f70b4 |
protected:
|
|
Packit |
8f70b4 |
prf_res ProcessFile(const char *d,const FileInfo *fi);
|
|
Packit |
8f70b4 |
void Finish();
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
FinderJob_List(FileAccess *s,ArgV *a,FDStream *o);
|
|
Packit |
8f70b4 |
void DoLongListing(bool yes=true) { long_listing=yes; }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
int Done() { return FinderJob::Done() && buf->Done(); }
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#endif //FINDJOB_H
|