blob: fbf288e50a94f7b6cad42951fa64ce9083e856df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// **********************************************************************
//
// Copyright (c) 2002
// Mutable Realms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <IcePatch/FileLocator.h>
#include <IcePatch/Util.h>
#include <IcePatch/IcePatchI.h>
using namespace std;
using namespace Ice;
using namespace IcePatch;
IcePatch::FileLocator::FileLocator(const Ice::ObjectAdapterPtr& adapter) :
_directory(new DirectoryI(adapter)),
_regular(new RegularI(adapter))
{
}
ObjectPtr
IcePatch::FileLocator::locate(const Current& current, LocalObjectPtr&)
{
//
// Check whether the path is valid.
//
string path = identityToPath(current.id);
if(path.empty())
{
return 0;
}
if(path[0] == '/') // Example: /usr/mail/foo
{
return 0;
}
//
// Note: We could make the following rule more selective, to allow
// names such as "foo..bar". But since such names are rather
// uncommon, we disallow ".." altogether, to be on the safe side.
//
if(path.find("..") != string::npos) // Example: foo/../..
{
return 0;
}
if(path.size() >= 2 &&
::tolower(path[0]) >= 'a' && ::tolower(path[0]) <= 'z' && path[1] == ':') // Example: c:\blah
{
return 0;
}
if(ignoreSuffix(path)) // Example: foo.md5
{
return 0;
}
FileInfo info;
try
{
info = getFileInfo(path, true);
}
catch(const FileAccessException& ex)
{
Warning out(current.adapter->getCommunicator()->getLogger());
out << ex << ":\n" << ex.reason;
return 0;
}
switch(info.type)
{
case FileTypeDirectory:
{
return _directory;
}
case FileTypeRegular:
{
return _regular;
}
default:
{
return 0;
}
}
}
void
IcePatch::FileLocator::finished(const Current& current, const ObjectPtr&,
const LocalObjectPtr&)
{
// Nothing to do.
}
void
IcePatch::FileLocator::deactivate()
{
//
// Break cyclic dependencies.
//
_directory = 0;
_regular = 0;
}
|