600
|
1 |
/*
|
|
2 |
* Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <new>
|
|
19 |
#include <stdio.h>
|
|
20 |
#include <stdlib.h>
|
|
21 |
#include <string>
|
|
22 |
#include <cstring>
|
|
23 |
#include <time.h>
|
|
24 |
#include <map>
|
|
25 |
#include <iostream>
|
|
26 |
#include <fstream>
|
|
27 |
#include <filesystem.hpp>
|
|
28 |
#include <thread/mutex.hpp>
|
|
29 |
|
|
30 |
#include "cache/cacheexception.hpp"
|
|
31 |
#include "cache/cacheentry.hpp"
|
|
32 |
#include "cache/cache.hpp"
|
|
33 |
#include "cache/cachevalidator.hpp"
|
|
34 |
|
|
35 |
using namespace std ;
|
|
36 |
CacheValidator* CacheValidator::Only = (CacheValidator*)0;
|
|
37 |
|
|
38 |
|
|
39 |
CacheValidator* CacheValidator::GetInstance(void) throw (CacheException)
|
|
40 |
{
|
|
41 |
if(! CacheValidator::Only)
|
|
42 |
{
|
|
43 |
CacheValidator::Only = new (nothrow) CacheValidator();
|
|
44 |
if(! CacheValidator::Only)
|
|
45 |
throw CacheException(CacheException::RESOURCE_ALLOCATION_FAILURE);
|
|
46 |
}
|
|
47 |
|
|
48 |
return CacheValidator::Only;
|
|
49 |
}
|
|
50 |
|
|
51 |
|
|
52 |
CacheEntry* CacheValidator::Validate(const char* OriginalFilename, int CurrentCompressionID)
|
|
53 |
{
|
|
54 |
if(! OriginalFilename)
|
|
55 |
return (CacheEntry*)0;
|
|
56 |
|
|
57 |
//an executable will be validated if its creation time does not altered and the compression method is not different against previous image build used.
|
|
58 |
CacheEntry* entryref = Cache::GetInstance()->GetEntryList(OriginalFilename);
|
|
59 |
if(! entryref)
|
|
60 |
{
|
|
61 |
return (CacheEntry*)0;
|
|
62 |
}
|
609
|
63 |
|
|
64 |
boost::filesystem::path originalfile(OriginalFilename);
|
|
65 |
time_t originalcreationtime = last_write_time(originalfile);
|
|
66 |
string creationtime(ctime(&originalcreationtime));
|
|
67 |
size_t newlinepos = creationtime.find("\n");
|
|
68 |
while(newlinepos != string::npos)
|
|
69 |
{
|
|
70 |
creationtime.erase(newlinepos, 1);
|
|
71 |
newlinepos = creationtime.find(("\n"));
|
|
72 |
}
|
600
|
73 |
while(entryref)
|
|
74 |
{
|
609
|
75 |
if((creationtime.compare(entryref->GetOriginalFileCreateTime())== 0) && (atoi(entryref->GetCachedFileCompressionID())==CurrentCompressionID))
|
600
|
76 |
{
|
|
77 |
boost::filesystem::path cachedfile(entryref->GetCachedFilename());
|
|
78 |
string filename = cachedfile.file_string();
|
|
79 |
ifstream filecontentreader(filename.c_str(), ios_base::in | ios_base::binary);
|
|
80 |
if(! filecontentreader.is_open()){
|
|
81 |
cerr << "Cannot open cached file " << filename << endl ;
|
|
82 |
return NULL;
|
|
83 |
}
|
|
84 |
filecontentreader.seekg(0, ios_base::end);
|
|
85 |
int contentlength = filecontentreader.tellg();
|
|
86 |
char* bufferref = new char[contentlength + 1];
|
|
87 |
filecontentreader.seekg(0, ios_base::beg);
|
|
88 |
filecontentreader.read(bufferref, contentlength);
|
|
89 |
bufferref[contentlength] = 0 ;
|
|
90 |
entryref->SetCachedFileBuffer(bufferref, contentlength);
|
|
91 |
delete []bufferref;
|
|
92 |
|
|
93 |
cout << "Using cached" << OriginalFilename << endl ;
|
|
94 |
|
|
95 |
return entryref;
|
|
96 |
}
|
|
97 |
|
|
98 |
entryref = entryref->GetNextEntry();
|
|
99 |
}
|
|
100 |
|
|
101 |
return (CacheEntry*)0;
|
|
102 |
}
|
|
103 |
|
|
104 |
|
|
105 |
CacheValidator::CacheValidator(void)
|
|
106 |
{
|
|
107 |
return;
|
|
108 |
}
|