Subversion Repositories tpanel

Rev

Rev 119 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 119 Rev 125
Line 24... Line 24...
24
#include <filesystem>
24
#include <filesystem>
25
#endif
25
#endif
26
#include "expand.h"
26
#include "expand.h"
27
#include <assert.h>
27
#include <assert.h>
28
 
28
 
29
using namespace std;
-
 
30
#if __GNUC__ < 9 && !defined(__ANDROID__)
29
#if __GNUC__ < 9 && !defined(__ANDROID__)
31
   #if __cplusplus < 201703L
30
   #if __cplusplus < 201703L
32
      #warning "Your C++ compiler seems to have no support for C++17 standard!"
31
      #warning "Your C++ compiler seems to have no support for C++17 standard!"
33
   #endif
32
   #endif
34
   #include <experimental/filesystem>
33
   #include <experimental/filesystem>
Line 46... Line 45...
46
#   include <filesystem>
45
#   include <filesystem>
47
    namespace fs = std::filesystem;
46
    namespace fs = std::filesystem;
48
#  endif
47
#  endif
49
#endif
48
#endif
50
 
49
 
-
 
50
using namespace std;
-
 
51
 
51
void Expand::setFileName (const string &fn)
52
void Expand::setFileName (const string &fn)
52
{
53
{
53
	fname.assign(fn);
54
	fname.assign(fn);
54
}
55
}
55
 
56
 
Line 95... Line 96...
95
	if (ret != Z_OK)
96
	if (ret != Z_OK)
96
	{
97
	{
97
		zerr(ret);
98
		zerr(ret);
98
		fclose(source);
99
		fclose(source);
99
		fclose(dest);
100
		fclose(dest);
100
		fs::remove(target);
101
        fs::remove(target);
101
		return ret;
102
		return ret;
102
	}
103
	}
103
 
104
 
104
	do
105
	do
105
	{
106
	{
Line 109... Line 110...
109
		{
110
		{
110
			(void)inflateEnd(&strm);
111
			(void)inflateEnd(&strm);
111
			cerr << "Error reading from file " << fname << "!" << endl;
112
			cerr << "Error reading from file " << fname << "!" << endl;
112
			fclose(source);
113
			fclose(source);
113
			fclose(dest);
114
			fclose(dest);
114
			fs::remove(target);
115
            fs::remove(target);
115
			return Z_ERRNO;
116
			return Z_ERRNO;
116
		}
117
		}
117
 
118
 
118
		if (strm.avail_in == 0)
119
		if (strm.avail_in == 0)
119
			break;
120
			break;
Line 135... Line 136...
135
				case Z_DATA_ERROR:
136
				case Z_DATA_ERROR:
136
				case Z_MEM_ERROR:
137
				case Z_MEM_ERROR:
137
					(void)inflateEnd(&strm);
138
					(void)inflateEnd(&strm);
138
					fclose(source);
139
					fclose(source);
139
					fclose(dest);
140
					fclose(dest);
140
					fs::remove(target);
141
                    fs::remove(target);
141
					zerr(ret);
142
					zerr(ret);
142
					return ret;
143
					return ret;
143
			}
144
			}
144
 
145
 
145
			have = CHUNK - strm.avail_out;
146
			have = CHUNK - strm.avail_out;
Line 148... Line 149...
148
			{
149
			{
149
				(void)inflateEnd(&strm);
150
				(void)inflateEnd(&strm);
150
				cerr << "Error on writing to file " << target << "!" << endl;
151
				cerr << "Error on writing to file " << target << "!" << endl;
151
				fclose(source);
152
				fclose(source);
152
				fclose(dest);
153
				fclose(dest);
153
				fs::remove(target);
154
                fs::remove(target);
154
				return Z_ERRNO;
155
				return Z_ERRNO;
155
			}
156
			}
156
		}
157
		}
157
		while (strm.avail_out == 0);
158
		while (strm.avail_out == 0);
158
		// done when inflate() says it's done
159
		// done when inflate() says it's done
159
	}
160
	}
160
	while (ret != Z_STREAM_END);
161
	while (ret != Z_STREAM_END);
161
	// clean up and return
162
	// clean up and return
162
	(void)inflateEnd(&strm);
163
	(void)inflateEnd(&strm);
163
	fclose(source);
164
	fclose(source);
164
	fclose(dest);
165
    fclose(dest);
165
	fs::remove(fname);
166
    fs::remove(fname);
166
	fs::rename(target, fname);
167
    fs::rename(target, fname);
167
	return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
168
    return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
168
}
169
}
169
 
170
 
170
void Expand::zerr(int ret)
171
void Expand::zerr(int ret)
171
{
172
{
172
    switch (ret)
173
    switch (ret)