replace GetFileModTime with GetFileHash
This commit is contained in:
@@ -115,9 +115,9 @@ int RageFileDriver::GetFileSizeInBytes( const CString &sPath )
|
||||
return FDB->GetFileSize( sPath );
|
||||
}
|
||||
|
||||
int RageFileDriver::GetFileModTime( const CString &sPath )
|
||||
int RageFileDriver::GetFileHash( const CString &sPath )
|
||||
{
|
||||
return FDB->GetFileModTime( sPath );
|
||||
return FDB->GetFileHash( sPath );
|
||||
}
|
||||
|
||||
void RageFileDriver::FlushDirCache( const CString &sPath )
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
virtual void GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo );
|
||||
virtual RageFileManager::FileType GetFileType( const CString &sPath );
|
||||
virtual int GetFileSizeInBytes( const CString &sFilePath );
|
||||
virtual int GetFileModTime( const CString &sPath );
|
||||
virtual int GetFileHash( const CString &sPath );
|
||||
virtual int GetPathValue( const CString &path );
|
||||
virtual bool Ready() { return true; } /* see RageFileManager::MountpointIsReady */
|
||||
virtual void FlushDirCache( const CString &sPath );
|
||||
|
||||
@@ -69,7 +69,7 @@ void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path )
|
||||
f.SetName( fd.cFileName );
|
||||
f.dir = !!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
f.size = fd.nFileSizeLow;
|
||||
f.mtime = fd.ftLastWriteTime.dwLowDateTime;
|
||||
f.hash = fd.ftLastWriteTime.dwLowDateTime;
|
||||
|
||||
fs.files.insert(f);
|
||||
} while( FindNextFile( hFind, &fd ) );
|
||||
@@ -112,7 +112,7 @@ void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path )
|
||||
} else {
|
||||
f.dir = (st.st_mode & S_IFDIR);
|
||||
f.size = st.st_size;
|
||||
f.mtime = st.st_mtime;
|
||||
f.hash = st.st_mtime;
|
||||
}
|
||||
|
||||
fs.files.insert(f);
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
RageFileDriverMountpoints(): RageFileDriver( new FilenameDB ) { }
|
||||
RageFileObj *Open( const CString &path, RageFile::OpenMode mode, RageFile &p, int &err )
|
||||
{
|
||||
err = EINVAL;
|
||||
err = (mode == RageFile::WRITE)? EINVAL:ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
void FlushDirCache( const CString &sPath ) { }
|
||||
@@ -257,14 +257,14 @@ int RageFileManager::GetFileSizeInBytes( const CString &sPath )
|
||||
return -1;
|
||||
}
|
||||
|
||||
int RageFileManager::GetFileModTime( const CString &sPath )
|
||||
int RageFileManager::GetFileHash( const CString &sPath )
|
||||
{
|
||||
for( unsigned i = 0; i < g_Drivers.size(); ++i )
|
||||
{
|
||||
const CString p = g_Drivers[i].GetPath( sPath );
|
||||
if( p.size() == 0 )
|
||||
continue;
|
||||
int ret = g_Drivers[i].driver->GetFileModTime( p );
|
||||
int ret = g_Drivers[i].driver->GetFileHash( p );
|
||||
if( ret != -1 )
|
||||
return ret;
|
||||
}
|
||||
@@ -288,7 +288,6 @@ RageFileObj *RageFileManager::Open( const CString &sPath, RageFile::OpenMode mod
|
||||
if( mode == RageFile::WRITE )
|
||||
return OpenForWriting( sPath, mode, p, err );
|
||||
|
||||
/* XXX: WRITE logic */
|
||||
for( unsigned i = 0; i < g_Drivers.size(); ++i )
|
||||
{
|
||||
const CString path = g_Drivers[i].GetPath( sPath );
|
||||
@@ -393,11 +392,6 @@ unsigned GetFileSizeInBytes( const CString &sPath )
|
||||
return FILEMAN->GetFileSizeInBytes( sPath );
|
||||
}
|
||||
|
||||
int GetFileModTime( const CString &sPath )
|
||||
{
|
||||
return FILEMAN->GetFileModTime( sPath );
|
||||
}
|
||||
|
||||
void GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo )
|
||||
{
|
||||
FILEMAN->GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo );
|
||||
@@ -408,3 +402,25 @@ void FlushDirCache()
|
||||
FILEMAN->FlushDirCache( "" );
|
||||
}
|
||||
|
||||
|
||||
unsigned int GetHashForFile( const CString &sPath )
|
||||
{
|
||||
return GetHashForString( sPath ) + FILEMAN->GetFileHash( sPath );
|
||||
}
|
||||
|
||||
unsigned int GetHashForDirectory( const CString &sDir )
|
||||
{
|
||||
unsigned int hash = 0;
|
||||
|
||||
hash += GetHashForFile( sDir );
|
||||
|
||||
CStringArray arrayFiles;
|
||||
GetDirListing( sDir+"*", arrayFiles, false );
|
||||
for( unsigned i=0; i<arrayFiles.size(); i++ )
|
||||
{
|
||||
const CString sFilePath = sDir + arrayFiles[i];
|
||||
hash += GetHashForFile( sFilePath );
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
bool DoesFileExist( const CString &sPath );
|
||||
|
||||
int GetFileSizeInBytes( const CString &sPath );
|
||||
int GetFileModTime( const CString &sPath );
|
||||
int GetFileHash( const CString &sPath );
|
||||
|
||||
void Mount( CString Type, CString RealPath, CString MountPoint );
|
||||
bool IsMounted( CString MountPoint );
|
||||
|
||||
@@ -354,34 +354,6 @@ unsigned int GetHashForString ( const CString &s )
|
||||
return crc;
|
||||
}
|
||||
|
||||
unsigned int GetHashForFile( const CString &sPath )
|
||||
{
|
||||
unsigned int hash = 0;
|
||||
|
||||
hash += GetHashForString( sPath );
|
||||
hash += GetFileSizeInBytes( sPath );
|
||||
hash += GetFileModTime( sPath );
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
unsigned int GetHashForDirectory( const CString &sDir )
|
||||
{
|
||||
unsigned int hash = 0;
|
||||
|
||||
hash += GetHashForFile( sDir );
|
||||
|
||||
CStringArray arrayFiles;
|
||||
GetDirListing( sDir+"*", arrayFiles, false );
|
||||
for( unsigned i=0; i<arrayFiles.size(); i++ )
|
||||
{
|
||||
const CString sFilePath = sDir + arrayFiles[i];
|
||||
hash += GetHashForFile( sFilePath );
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/* Return true if "dir" is empty or does not exist. */
|
||||
bool DirectoryIsEmpty( const CString &dir )
|
||||
{
|
||||
|
||||
@@ -282,7 +282,6 @@ bool IsAFile( const CString &sPath );
|
||||
bool IsADirectory( const CString &sPath );
|
||||
bool ResolvePath(CString &path);
|
||||
unsigned GetFileSizeInBytes( const CString &sFilePath );
|
||||
int GetFileModTime( const CString &sPath );
|
||||
void FlushDirCache();
|
||||
|
||||
// helper file functions used by Bookkeeper and ProfileManager
|
||||
|
||||
@@ -69,12 +69,12 @@ int FileSet::GetFileSize(const CString &path) const
|
||||
return i->size;
|
||||
}
|
||||
|
||||
int FileSet::GetFileModTime(const CString &path) const
|
||||
int FileSet::GetFileHash(const CString &path) const
|
||||
{
|
||||
set<File>::const_iterator i = files.find( File(path) );
|
||||
if(i == files.end())
|
||||
return -1;
|
||||
return i->mtime;
|
||||
return i->hash + i->size;
|
||||
}
|
||||
|
||||
/* Given "foo/bar/baz/" or "foo/bar/baz", return "foo/bar/" and "baz". */
|
||||
@@ -117,12 +117,12 @@ int FilenameDB::GetFileSize( const CString &sPath )
|
||||
return fs.GetFileSize(Name);
|
||||
}
|
||||
|
||||
int FilenameDB::GetFileModTime( const CString &sPath )
|
||||
int FilenameDB::GetFileHash( const CString &sPath )
|
||||
{
|
||||
CString Dir, Name;
|
||||
SplitPath(sPath, Dir, Name);
|
||||
FileSet &fs = GetFileSet( Dir );
|
||||
return fs.GetFileModTime(Name);
|
||||
return fs.GetFileHash(Name);
|
||||
}
|
||||
|
||||
/* XXX: this won't work right for URIs, eg \\foo\bar */
|
||||
@@ -243,7 +243,7 @@ void FilenameDB::AddFileSet( CString sPath, FileSet *fs )
|
||||
|
||||
/* Add the file or directory "sPath". sPath is a directory if it ends with
|
||||
* a slash. */
|
||||
void FilenameDB::AddFile( const CString &sPath, int size, int mtime, void *priv )
|
||||
void FilenameDB::AddFile( const CString &sPath, int size, int hash, void *priv )
|
||||
{
|
||||
vector<CString> parts;
|
||||
split( sPath, "/", parts, false );
|
||||
@@ -272,7 +272,7 @@ void FilenameDB::AddFile( const CString &sPath, int size, int mtime, void *priv
|
||||
if( !IsDir )
|
||||
{
|
||||
f.size = size;
|
||||
f.mtime = mtime;
|
||||
f.hash = hash;
|
||||
f.priv = priv;
|
||||
}
|
||||
fs.files.insert( f );
|
||||
@@ -347,22 +347,3 @@ void FilenameDB::GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDi
|
||||
|
||||
bool ResolvePath(CString &path) { return true; } // XXX
|
||||
|
||||
|
||||
#if 0
|
||||
bool DoesFileExist( const CString &sPath ) { return FDB.GetFileType( sPath ) != TTYPE_NONE; }
|
||||
bool IsAFile( const CString &sPath ) { return FDB.GetFileType( sPath ) == TTYPE_FILE; }
|
||||
bool IsADirectory( const CString &sPath ) { return FDB.GetFileType( sPath ) == TTYPE_DIR; }
|
||||
int GetFileModTime( const CString &sPath ) { return FDB.GetFileModTime(sPath); }
|
||||
unsigned GetFileSizeInBytes( const CString &sPath )
|
||||
{
|
||||
int ret = FDB.GetFileSize(sPath);
|
||||
// LOG->Trace("file '%s' size %i", sPath.c_str(), ret);
|
||||
if( ret == -1 )
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo )
|
||||
{
|
||||
FDB.GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo );
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -23,15 +23,15 @@ struct File
|
||||
int size;
|
||||
/* Modification time of the file. The contents of this is undefined, except that
|
||||
* when the file has been modified, this value will change. */
|
||||
int mtime;
|
||||
int hash;
|
||||
|
||||
/* Private data, for RageFileDrivers. */
|
||||
void *priv;
|
||||
File() { dir=false; size=-1; mtime=-1; priv=NULL;}
|
||||
File() { dir=false; size=-1; hash=-1; priv=NULL;}
|
||||
File( const CString &fn )
|
||||
{
|
||||
SetName( fn );
|
||||
dir=false; size=-1; mtime=-1; priv=NULL;
|
||||
dir=false; size=-1; hash=-1; priv=NULL;
|
||||
}
|
||||
|
||||
bool operator== (const File &rhs) const { return lname==rhs.lname; }
|
||||
@@ -58,7 +58,7 @@ struct FileSet
|
||||
|
||||
FileType GetFileType( const CString &path ) const;
|
||||
int GetFileSize(const CString &path) const;
|
||||
int GetFileModTime(const CString &path) const;
|
||||
int GetFileHash(const CString &path) const;
|
||||
};
|
||||
|
||||
class FilenameDB
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
ExpireSeconds( -1 ) { }
|
||||
virtual FilenameDB::~FilenameDB() { FlushDirCache(); }
|
||||
|
||||
void AddFile( const CString &sPath, int size, int mtime, void *priv=NULL );
|
||||
void AddFile( const CString &sPath, int size, int hash, void *priv=NULL );
|
||||
File *GetFile( const CString &path );
|
||||
|
||||
/* This handles at most two * wildcards. If we need anything more complicated,
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
|
||||
FileType GetFileType( const CString &path );
|
||||
int GetFileSize(const CString &path);
|
||||
int GetFileModTime( const CString &sFilePath );
|
||||
int GetFileHash( const CString &sFilePath );
|
||||
void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo );
|
||||
|
||||
void FlushDirCache();
|
||||
|
||||
Reference in New Issue
Block a user