1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
10 #ifndef ICE_PATCH2_UTIL_H
11 #define ICE_PATCH2_UTIL_H
14 #include <IcePatch2/FileInfo.h>
20 ICE_PATCH2_API
extern const char* checksumFile
;
21 ICE_PATCH2_API
extern const char* logFile
;
23 ICE_PATCH2_API
std::string
lastError();
25 ICE_PATCH2_API
std::string
bytesToString(const Ice::ByteSeq
&);
26 ICE_PATCH2_API
Ice::ByteSeq
stringToBytes(const std::string
&);
28 ICE_PATCH2_API
std::string
simplify(const std::string
&);
30 ICE_PATCH2_API
bool isRoot(const std::string
&);
32 ICE_PATCH2_API
std::string
getSuffix(const std::string
&);
33 ICE_PATCH2_API
std::string
getWithoutSuffix(const std::string
&);
34 ICE_PATCH2_API
bool ignoreSuffix(const std::string
&);
36 ICE_PATCH2_API
std::string
getBasename(const std::string
&);
37 ICE_PATCH2_API
std::string
getDirname(const std::string
&);
39 ICE_PATCH2_API
void rename(const std::string
&, const std::string
&);
41 ICE_PATCH2_API
void remove(const std::string
&);
42 ICE_PATCH2_API
void removeRecursive(const std::string
&);
44 ICE_PATCH2_API
Ice::StringSeq
readDirectory(const std::string
&);
46 ICE_PATCH2_API
void createDirectory(const std::string
&);
47 ICE_PATCH2_API
void createDirectoryRecursive(const std::string
&);
49 ICE_PATCH2_API
void compressBytesToFile(const std::string
&, const Ice::ByteSeq
&, Ice::Int
);
50 ICE_PATCH2_API
void decompressFile(const std::string
&);
51 ICE_PATCH2_API
void setFileFlags(const std::string
&, const FileInfo
&);
53 struct FileInfoEqual
: public std::binary_function
<const FileInfo
&, const FileInfo
&, bool>
56 operator()(const FileInfo
& lhs
, const FileInfo
& rhs
)
58 if(lhs
.path
!= rhs
.path
)
64 // For the size portion of the comparison, we only distinquish
65 // between file (size >= 0) and directory (size == -1). We do
66 // not take the actual size into account, as it might be set
67 // to 0 if no compressed file is available.
69 Ice::Int lsz
= lhs
.size
> 0 ? 0 : lhs
.size
;
70 Ice::Int rsz
= rhs
.size
> 0 ? 0 : rhs
.size
;
76 if(lhs
.executable
!= rhs
.executable
)
81 return lhs
.checksum
== rhs
.checksum
;
85 struct FileInfoWithoutFlagsLess
: public std::binary_function
<const FileInfo
&, const FileInfo
&, bool>
88 operator()(const FileInfo
& lhs
, const FileInfo
& rhs
)
90 return compareWithoutFlags(lhs
, rhs
) < 0;
94 compareWithoutFlags(const FileInfo
& lhs
, const FileInfo
& rhs
)
96 if(lhs
.path
< rhs
.path
)
100 else if(rhs
.path
< lhs
.path
)
106 // For the size portion of the comparison, we only distinquish
107 // between file (size >= 0) and directory (size == -1). We do
108 // not take the actual size into account, as it might be set
109 // to 0 if no compressed file is available.
111 Ice::Int lsz
= lhs
.size
> 0 ? 0 : lhs
.size
;
112 Ice::Int rsz
= rhs
.size
> 0 ? 0 : rhs
.size
;
122 if(lhs
.checksum
< rhs
.checksum
)
126 else if(rhs
.checksum
< lhs
.checksum
)
135 struct FileInfoLess
: public FileInfoWithoutFlagsLess
138 operator()(const FileInfo
& lhs
, const FileInfo
& rhs
)
140 int rc
= compareWithoutFlags(lhs
, rhs
);
150 return lhs
.executable
< rhs
.executable
;
154 class ICE_PATCH2_API GetFileInfoSeqCB
158 virtual ~GetFileInfoSeqCB() { }
160 virtual bool remove(const std::string
&) = 0;
161 virtual bool checksum(const std::string
&) = 0;
162 virtual bool compress(const std::string
&) = 0;
165 ICE_PATCH2_API
bool getFileInfoSeq(const std::string
&, int, GetFileInfoSeqCB
*, FileInfoSeq
&);
166 ICE_PATCH2_API
bool getFileInfoSeqSubDir(const std::string
&, const std::string
&, int, GetFileInfoSeqCB
*, FileInfoSeq
&);
168 ICE_PATCH2_API
void saveFileInfoSeq(const std::string
&, const FileInfoSeq
&);
169 ICE_PATCH2_API
void loadFileInfoSeq(const std::string
&, FileInfoSeq
&);
171 ICE_PATCH2_API
bool readFileInfo(FILE*, FileInfo
&);
172 ICE_PATCH2_API
bool writeFileInfo(FILE*, const FileInfo
&);
177 Ice::ByteSeq checksum
;
180 typedef std::vector
<FileTree1
> FileTree1Seq
;
185 Ice::ByteSeq checksum
;
188 ICE_PATCH2_API
void getFileTree0(const FileInfoSeq
&, FileTree0
&);