imgtools/romtools/rofsbuild/src/cache/cache.cpp
author marvin shi <marvin.shi@nokia.com>
Wed, 17 Nov 2010 16:47:55 +0800
changeset 696 30aa553e9465
parent 600 6d08f4a05d93
permissions -rw-r--r--
features: bsym for rofsbuild and log input support for rombuild
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
/*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
* Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
* All rights reserved.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
* This component and the accompanying materials are made available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
* which accompanies this distribution, and is available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
* Initial Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
* Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
* Description: 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
*/
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
#include <new>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#include <cstring>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include <string>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include <iostream>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
#include <fstream>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
#include <queue>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#include <map>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
#include "e32image.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
#include <filesystem.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
#include <thread/thread.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
#include <thread/mutex.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
#include <thread/condition_variable.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
#include "cache/cacheexception.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
#include "cache/cacheentry.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
#include "cache/cacheablelist.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
#include "cache/cache.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
#include "cache/cachegenerator.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
#include "cache/cachevalidator.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
#include "cache/cachemanager.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
#include <malloc.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
#ifdef __LINUX__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
#define _alloca alloca
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
Cache* Cache::Only = (Cache*)0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
Cache* Cache::GetInstance(void) throw (CacheException)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
	if(! Cache::Only)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
		Cache::Only = new (std::nothrow) Cache();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
		if(! Cache::Only)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
			throw CacheException(CacheException::RESOURCE_ALLOCATION_FAILURE);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
	return Cache::Only;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
void Cache::Initialize(void) throw (CacheException)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
	//create and open cache meta data file.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
	 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
	 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	metafile = CacheManager::GetInstance()->GetCacheRoot();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
	metafile +=  "/.rofsmeta"; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
	boost::filesystem::path metafilepath(metafile.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
	if(!exists(metafilepath))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
		//create cache root directory if it's not present.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
		boost::filesystem::path createcacheroot(CacheManager::GetInstance()->GetCacheRoot());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
		create_directory(createcacheroot);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
		//create cache index file.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
		ofstream openmetafile(metafilepath.file_string().c_str(), ios_base::app | ios_base::out);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
		if(! openmetafile.is_open())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
			throw CacheException(CacheException::CACHE_INVALID);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
		openmetafile.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
	printf("Loading cache meta file : %s\r\n", metafilepath.file_string().c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
	ifstream metafileref(metafilepath.file_string().c_str(), ios_base::in);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
	if(! metafileref.is_open())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
		throw CacheException(CacheException::HARDDRIVE_FAILURE);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
	//read ROFS meta file and construct entry map.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
	string inboundbuffer;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
	while(getline(metafileref, inboundbuffer))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
		//validate cache index record.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
		if(! ValidateEntry(inboundbuffer))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
			throw CacheException(CacheException::CACHE_INVALID);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
		//instantiate a new instance of class CacheEntry.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
		CacheEntry* entryref = new (nothrow) CacheEntry();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
		if(!entryref)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
			throw CacheException(CacheException::RESOURCE_ALLOCATION_FAILURE);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
		//set entry's attributes.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
		char* attrwalker  = (char*)_alloca(inboundbuffer.length() + 1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
		memcpy(attrwalker,inboundbuffer.c_str(),inboundbuffer.length() + 1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
		 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
		char* start = attrwalker ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
		while(*start != ';')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
			start++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
		*start++ = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
		entryref->SetOriginalFilename(attrwalker);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
		attrwalker = start;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
		while(*start != ';')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
			start++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
		*start++ = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
		entryref->SetOriginalFileCreateTime(attrwalker);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
		attrwalker = start;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
		while(*start != ';')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
			start++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
		*start++ = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
		entryref->SetOriginalFileCompression(attrwalker);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
		attrwalker = start;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
		while(*start != ';')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
			start++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
		*start++ = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
		entryref->SetCachedFilename(attrwalker);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
		attrwalker = start;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
		entryref->SetCachedFileCompression(attrwalker);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
		//add newly created entry into entry-map.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
		string newentrystring(entryref->GetOriginalFilename());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
		CacheEntry* existentryref = entrymap[newentrystring];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
		if(existentryref) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
			while(existentryref->GetNextEntry())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
				existentryref = existentryref->GetNextEntry();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
			existentryref->AppendEntry(entryref);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
		else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
			entrymap[newentrystring] = entryref;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
		//reinitialize inbound buffer.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
		inboundbuffer.clear(); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
CacheEntry* Cache::GetEntryList(const char* OriginalFilename)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
	//retrieval could be performed concurrently.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
	boost::lock_guard<boost::mutex> lock(cachemutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
	string originalfile(OriginalFilename);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
	CacheEntry* resultentries = entrymap[originalfile];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
	return resultentries;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
void Cache::AddEntry(const char* OriginalFilename, CacheEntry* EntryRef)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
	string originalfile(OriginalFilename);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
	//addtions could be performed concurrently.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
	boost::lock_guard<boost::mutex> lock(cachemutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
	entrymap[originalfile] = EntryRef;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
void Cache::CloseCache(void) throw (CacheException)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
	//open up the cache meta file.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
	boost::filesystem::path metafilepath(metafile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
	ofstream metafileref;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
	if(! exists(metafilepath))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
		metafileref.open(metafilepath.file_string().c_str(), ios_base::out | ios_base::app);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
		metafileref.open(metafilepath.file_string().c_str(), ios_base::out | ios_base::trunc);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
	if(! metafileref.is_open())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
		throw CacheException(CacheException::HARDDRIVE_FAILURE);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
	//save cache meta onto hard drive along with changed cache files.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
	char* delimiter = ";";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
	map<string, CacheEntry*>::iterator mapitem;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
	for(mapitem=entrymap.begin(); mapitem != entrymap.end(); mapitem++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
		CacheEntry* concreteentryref = (*mapitem).second;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
		while(concreteentryref)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
			metafileref.write(concreteentryref->GetOriginalFilename(), strlen(concreteentryref->GetOriginalFilename()));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
			metafileref.write(delimiter, strlen(delimiter));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
			metafileref.write(concreteentryref->GetOriginalFileCreateTime(), strlen(concreteentryref->GetOriginalFileCreateTime()));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
			metafileref.write(delimiter, strlen(delimiter));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
			metafileref.write(concreteentryref->GetOriginalFileCompressionID(), strlen(concreteentryref->GetOriginalFileCompressionID()));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
			metafileref.write(delimiter, strlen(delimiter));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
			metafileref.write(concreteentryref->GetCachedFilename(), strlen(concreteentryref->GetCachedFilename()));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
			metafileref.write(delimiter, strlen(delimiter));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
			metafileref.write(concreteentryref->GetCachedFileCompressionID(), strlen(concreteentryref->GetCachedFileCompressionID()));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
			metafileref.write("\n", strlen("\n"));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
//			CacheEntry* tobedeletedentryref = concreteentryref;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
			concreteentryref = concreteentryref->GetNextEntry();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
//			delete tobedeletedentryref;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
	//close cache meta file.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
	metafileref.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
bool Cache::ValidateEntry(string& EntryRawText)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
	//an entry is formed as original_filename;original_file_create_time;original_file_compression_id;cached_filename;cached_file_compression_id(end of line - '\n')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
	//format validation.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
	int    semicolon         = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
	size_t semicolonposition = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
	while(1) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
		semicolonposition = EntryRawText.find(';', semicolonposition);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
		if(semicolonposition != string::npos) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
			semicolonposition++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
			semicolon++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
			break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
	if(semicolon != 4)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
		return false;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
	return true;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
Cache::Cache(void)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
	 return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242