|
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 LSCACHE_H
|
|
Packit |
8f70b4 |
#define LSCACHE_H
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#include <time.h>
|
|
Packit |
8f70b4 |
#include "Cache.h"
|
|
Packit |
8f70b4 |
#include "FileAccess.h"
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class Buffer;
|
|
Packit |
8f70b4 |
class FileAccess;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class LsCacheEntryLoc
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
friend class LsCache;
|
|
Packit |
8f70b4 |
xstring_c arg;
|
|
Packit |
8f70b4 |
SMTaskRef<FileAccess> loc; // no FileAccessRef -> no reuse here
|
|
Packit |
8f70b4 |
int mode;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
bool Matches(const FileAccess *p_loc,const char *a,int m);
|
|
Packit |
8f70b4 |
LsCacheEntryLoc(const FileAccess *p_loc,const char *a,int m);
|
|
Packit |
8f70b4 |
int EstimateSize() const { return xstrlen(arg)+(arg!=0); }
|
|
Packit |
8f70b4 |
const char *GetClosure() const;
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
class LsCacheEntryData
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
int err_code;
|
|
Packit |
8f70b4 |
xstring data;
|
|
Packit |
8f70b4 |
Ref<FileSet> afset; // associated file set
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
LsCacheEntryData(int e,const char *d,int l,const FileSet *fs);
|
|
Packit |
8f70b4 |
void SetData(int e,const char *d,int l,const FileSet *fs);
|
|
Packit |
8f70b4 |
void GetData(int *e,const char **d,int *l,const FileSet **fs);
|
|
Packit |
8f70b4 |
const FileSet *GetFileSet(const FileAccess *parser);
|
|
Packit |
8f70b4 |
void UpdateFileSet(const FileSet *fs) { if(afset) afset->Merge(fs); }
|
|
Packit |
8f70b4 |
int EstimateSize() const { return data.length()+(afset?afset->EstimateMemory():0); }
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class LsCacheEntry : public CacheEntry, public LsCacheEntryLoc, public LsCacheEntryData
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
int EstimateSize() const;
|
|
Packit |
8f70b4 |
LsCacheEntry(const FileAccess *p_loc,const char *a,int m,int e,const char *d,int l,const FileSet *fs);
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class LsCache : public Cache
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
LsCacheEntry *Find(const FileAccess *p_loc,const char *a,int m);
|
|
Packit |
8f70b4 |
LsCacheEntry *IterateFirst() { return (LsCacheEntry*)Cache::IterateFirst(); }
|
|
Packit |
8f70b4 |
LsCacheEntry *IterateNext() { return (LsCacheEntry*)Cache::IterateNext(); }
|
|
Packit |
8f70b4 |
LsCacheEntry *IterateDelete(){ return (LsCacheEntry*)Cache::IterateDelete(); }
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
LsCache();
|
|
Packit |
8f70b4 |
void Add(const FileAccess *p_loc,const char *a,int m,int err,const char *d,int l,const FileSet *f=0);
|
|
Packit |
8f70b4 |
void Add(const FileAccess *p_loc,const char *a,int m,int err,const Buffer *ubuf,const FileSet *f=0);
|
|
Packit |
8f70b4 |
bool Find(const FileAccess *p_loc,const char *a,int m,int *err,const char **d, int *l,const FileSet **f=0);
|
|
Packit |
8f70b4 |
const FileSet *FindFileSet(const FileAccess *p_loc,const char *a,int m);
|
|
Packit |
8f70b4 |
void UpdateFileSet(const FileAccess *p_loc,const char *a,int m,const FileSet *fs);
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
int IsDirectory(const FileAccess *p_loc,const char *dir);
|
|
Packit |
8f70b4 |
void SetDirectory(const FileAccess *p_loc, const char *path, bool dir);
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
enum change_mode { FILE_CHANGED, DIR_CHANGED, TREE_CHANGED };
|
|
Packit |
8f70b4 |
void Changed(change_mode m,const FileAccess *f,const char *what);
|
|
Packit |
8f70b4 |
void FileChanged(const FileAccess *f,const char *file)
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
Changed(FILE_CHANGED,f,file);
|
|
Packit |
8f70b4 |
}
|
|
Packit |
8f70b4 |
void DirectoryChanged(const FileAccess *f,const char *dir)
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
Changed(DIR_CHANGED,f,dir);
|
|
Packit |
8f70b4 |
}
|
|
Packit |
8f70b4 |
void TreeChanged(const FileAccess *f,const char *dir)
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
Changed(TREE_CHANGED,f,dir);
|
|
Packit |
8f70b4 |
}
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void List();
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#endif//LSCACHE_H
|