qsavefile.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qsavefile.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9QSaveFilePrivate::QSaveFilePrivate()-
10 : writeError(QFileDevice::NoError),-
11 useTemporaryFile(true),-
12 directWriteFallback(false)-
13{-
14}
executed 581 times by 7 tests: end of block
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
581
15-
16QSaveFilePrivate::~QSaveFilePrivate()-
17{-
18}-
19QSaveFile::QSaveFile(QObject *parent)-
20 : QFileDevice(*new QSaveFilePrivate, parent)-
21{-
22}
never executed: end of block
0
23-
24-
25-
26QSaveFile::QSaveFile(const QString &name)-
27 : QFileDevice(*new QSaveFilePrivate, 0)-
28{-
29 QSaveFilePrivate * const d = d_func();-
30 d->fileName = name;-
31}
executed 581 times by 7 tests: end of block
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
581
32-
33-
34-
35-
36QSaveFile::QSaveFile(const QString &name, QObject *parent)-
37 : QFileDevice(*new QSaveFilePrivate, parent)-
38{-
39 QSaveFilePrivate * const d = d_func();-
40 d->fileName = name;-
41}
never executed: end of block
0
42-
43-
44-
45-
46QSaveFile::~QSaveFile()-
47{-
48 QSaveFilePrivate * const d = d_func();-
49 QFileDevice::close();-
50 if (d->fileEngine
d->fileEngineDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSettings
FALSEevaluated 578 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
) {
3-578
51 d->fileEngine->remove();-
52 delete d->fileEngine;-
53 d->fileEngine = 0;-
54 }
executed 3 times by 1 test: end of block
Executed by:
  • tst_QSettings
3
55}
executed 581 times by 7 tests: end of block
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
581
56-
57-
58-
59-
60-
61-
62-
63QString QSaveFile::fileName() const-
64{-
65 return
executed 12 times by 1 test: return d_func()->fileName;
Executed by:
  • tst_QSaveFile
d_func()->fileName;
executed 12 times by 1 test: return d_func()->fileName;
Executed by:
  • tst_QSaveFile
12
66}-
67-
68-
69-
70-
71-
72-
73-
74void QSaveFile::setFileName(const QString &name)-
75{-
76 d_func()->fileName = name;-
77}
never executed: end of block
0
78bool QSaveFile::open(OpenMode mode)-
79{-
80 QSaveFilePrivate * const d = d_func();-
81 if (isOpen()
isOpen()Description
TRUEnever evaluated
FALSEevaluated 583 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
) {
0-583
82 QMessageLogger(__FILE__, 185, __PRETTY_FUNCTION__).warning("QSaveFile::open: File (%s) already open", QString(fileName()).toLocal8Bit().constData());-
83 return
never executed: return false;
false;
never executed: return false;
0
84 }-
85 unsetError();-
86 if ((
(mode & (ReadO...iteOnly)) == 0Description
TRUEnever evaluated
FALSEevaluated 583 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
mode & (ReadOnly | WriteOnly)) == 0
(mode & (ReadO...iteOnly)) == 0Description
TRUEnever evaluated
FALSEevaluated 583 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
) {
0-583
87 QMessageLogger(__FILE__, 190, __PRETTY_FUNCTION__).warning("QSaveFile::open: Open mode not specified");-
88 return
never executed: return false;
false;
never executed: return false;
0
89 }-
90-
91 if ((mode & ReadOnly) || (mode & Append)) {-
92 QMessageLogger(__FILE__, 195, __PRETTY_FUNCTION__).warning("QSaveFile::open: Unsupported open mode 0x%x", int(mode));-
93 return
never executed: return false;
false;
never executed: return false;
0
94 }-
95-
96-
97 QFileInfo existingFile(d->fileName);-
98 if (existingFile.exists()
existingFile.exists()Description
TRUEevaluated 457 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
FALSEevaluated 126 times by 2 tests
Evaluated by:
  • tst_QSaveFile
  • tst_QSettings
&& !existingFile.isWritable()
!existingFile.isWritable()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 456 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
) {
1-457
99 d->setError(QFileDevice::WriteError, QSaveFile::tr("Existing file %1 is not writable").arg(d->fileName));-
100 d->writeError = QFileDevice::WriteError;-
101 return
executed 1 time by 1 test: return false;
Executed by:
  • tst_QSaveFile
false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QSaveFile
1
102 }-
103-
104 if (existingFile.isDir()
existingFile.isDir()Description
TRUEnever evaluated
FALSEevaluated 582 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
) {
0-582
105 d->setError(QFileDevice::WriteError, QSaveFile::tr("Filename refers to a directory"));-
106 d->writeError = QFileDevice::WriteError;-
107 return
never executed: return false;
false;
never executed: return false;
0
108 }-
109-
110-
111-
112 d->finalFileName = d->fileName;-
113 if (existingFile.isSymLink()
existingFile.isSymLink()Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 577 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
) {
5-577
114 int maxDepth = 128;-
115 while (--
--maxDepthDescription
TRUEevaluated 261 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
maxDepth
--maxDepthDescription
TRUEevaluated 261 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
&& existingFile.isSymLink()
existingFile.isSymLink()Description
TRUEevaluated 258 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSaveFile
)
2-261
116 existingFile.setFile(existingFile.symLinkTarget());
executed 258 times by 1 test: existingFile.setFile(existingFile.symLinkTarget());
Executed by:
  • tst_QSaveFile
258
117 if (maxDepth > 0
maxDepth > 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
)
2-3
118 d->finalFileName = existingFile.filePath();
executed 3 times by 1 test: d->finalFileName = existingFile.filePath();
Executed by:
  • tst_QSaveFile
3
119 }
executed 5 times by 1 test: end of block
Executed by:
  • tst_QSaveFile
5
120-
121 d->fileEngine = new QTemporaryFileEngine;-
122 static_cast<QTemporaryFileEngine *>(d->fileEngine)->initialize(d->finalFileName, 0666);-
123-
124 if (!d->fileEngine->open(mode | QIODevice::Unbuffered)
!d->fileEngine...e::Unbuffered)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 577 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
) {
5-577
125 QFileDevice::FileError err = d->fileEngine->error();-
126-
127 if (d->directWriteFallback
d->directWriteFallbackDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSaveFile
&& err == QFileDevice::OpenError
err == QFileDevice::OpenErrorDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEnever evaluated
&& (*
(*__errno_location ()) == 13Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEnever evaluated
__errno_location ()) == 13
(*__errno_location ()) == 13Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEnever evaluated
) {
0-3
128 delete d->fileEngine;-
129 d->fileEngine = QAbstractFileEngine::create(d->finalFileName);-
130 if (d->fileEngine->open(mode | QIODevice::Unbuffered)
d->fileEngine-...e::Unbuffered)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEnever evaluated
) {
0-2
131 d->useTemporaryFile = false;-
132 QFileDevice::open(mode);-
133 return
executed 2 times by 1 test: return true;
Executed by:
  • tst_QSaveFile
true;
executed 2 times by 1 test: return true;
Executed by:
  • tst_QSaveFile
2
134 }-
135 err = d->fileEngine->error();-
136 }
never executed: end of block
0
137-
138 if (err == QFileDevice::UnspecifiedError
err == QFileDe...specifiedErrorDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSaveFile
)
0-3
139 err = QFileDevice::OpenError;
never executed: err = QFileDevice::OpenError;
0
140 d->setError(err, d->fileEngine->errorString());-
141 delete d->fileEngine;-
142 d->fileEngine = 0;-
143 return
executed 3 times by 1 test: return false;
Executed by:
  • tst_QSaveFile
false;
executed 3 times by 1 test: return false;
Executed by:
  • tst_QSaveFile
3
144 }-
145-
146 d->useTemporaryFile = true;-
147 QFileDevice::open(mode);-
148 if (existingFile.exists()
existingFile.exists()Description
TRUEevaluated 453 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
FALSEevaluated 124 times by 2 tests
Evaluated by:
  • tst_QSaveFile
  • tst_QSettings
)
124-453
149 setPermissions(existingFile.permissions());
executed 453 times by 7 tests: setPermissions(existingFile.permissions());
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
453
150 return
executed 577 times by 7 tests: return true;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
true;
executed 577 times by 7 tests: return true;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
577
151}-
152-
153-
154-
155-
156-
157-
158-
159void QSaveFile::close()-
160{-
161 QMessageLogger(__FILE__, 264, __PRETTY_FUNCTION__).fatal("QSaveFile::close called");-
162}
never executed: end of block
0
163bool QSaveFile::commit()-
164{-
165 QSaveFilePrivate * const d = d_func();-
166 if (!d->fileEngine
!d->fileEngineDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 576 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
)
2-576
167 return
executed 2 times by 1 test: return false;
Executed by:
  • tst_QSaveFile
false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QSaveFile
2
168-
169 if (!isOpen()
!isOpen()Description
TRUEnever evaluated
FALSEevaluated 576 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
) {
0-576
170 QMessageLogger(__FILE__, 286, __PRETTY_FUNCTION__).warning("QSaveFile::commit: File (%s) is not open", QString(fileName()).toLocal8Bit().constData());-
171 return
never executed: return false;
false;
never executed: return false;
0
172 }-
173 QFileDevice::close();-
174-
175-
176 d->fileEngine->syncToDisk();-
177-
178 if (d->useTemporaryFile
d->useTemporaryFileDescription
TRUEevaluated 574 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
) {
2-574
179 if (d->writeError != QFileDevice::NoError
d->writeError ...evice::NoErrorDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 573 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
) {
1-573
180 d->fileEngine->remove();-
181 d->writeError = QFileDevice::NoError;-
182 delete d->fileEngine;-
183 d->fileEngine = 0;-
184 return
executed 1 time by 1 test: return false;
Executed by:
  • tst_QSaveFile
false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QSaveFile
1
185 }-
186-
187-
188 ((!(d->fileEngine)) ? qt_assert("d->fileEngine",__FILE__,304) : qt_noop());-
189 if (!d->fileEngine->renameOverwrite(d->finalFileName)
!d->fileEngine...finalFileName)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSaveFile
FALSEevaluated 572 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
) {
1-572
190 d->setError(d->fileEngine->error(), d->fileEngine->errorString());-
191 d->fileEngine->remove();-
192 delete d->fileEngine;-
193 d->fileEngine = 0;-
194 return
executed 1 time by 1 test: return false;
Executed by:
  • tst_QSaveFile
false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QSaveFile
1
195 }-
196 }
executed 572 times by 7 tests: end of block
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
572
197 delete d->fileEngine;-
198 d->fileEngine = 0;-
199 return
executed 574 times by 7 tests: return true;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
true;
executed 574 times by 7 tests: return true;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
574
200}-
201void QSaveFile::cancelWriting()-
202{-
203 QSaveFilePrivate * const d = d_func();-
204 if (!isOpen()
!isOpen()Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSaveFile
)
0-2
205 return;
never executed: return;
0
206 d->setError(QFileDevice::WriteError, QSaveFile::tr("Writing canceled by application"));-
207 d->writeError = QFileDevice::WriteError;-
208}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QSaveFile
2
209-
210-
211-
212-
213qint64 QSaveFile::writeData(const char *data, qint64 len)-
214{-
215 QSaveFilePrivate * const d = d_func();-
216 if (d->writeError != QFileDevice::NoError
d->writeError ...evice::NoErrorDescription
TRUEnever evaluated
FALSEevaluated 6672 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
)
0-6672
217 return
never executed: return -1;
-1;
never executed: return -1;
0
218-
219 const qint64 ret = QFileDevice::writeData(data, len);-
220-
221 if (d->error != QFileDevice::NoError
d->error != QF...evice::NoErrorDescription
TRUEnever evaluated
FALSEevaluated 6672 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
)
0-6672
222 d->writeError = d->error;
never executed: d->writeError = d->error;
0
223 return
executed 6672 times by 7 tests: return ret;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
ret;
executed 6672 times by 7 tests: return ret;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QSaveFile
  • tst_QSettings
  • tst_languageChange
6672
224}-
225void QSaveFile::setDirectWriteFallback(bool enabled)-
226{-
227 QSaveFilePrivate * const d = d_func();-
228 d->directWriteFallback = enabled;-
229}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QSaveFile
2
230-
231-
232-
233-
234-
235-
236-
237bool QSaveFile::directWriteFallback() const-
238{-
239 const QSaveFilePrivate * const d = d_func();-
240 return
executed 2 times by 1 test: return d->directWriteFallback;
Executed by:
  • tst_QSaveFile
d->directWriteFallback;
executed 2 times by 1 test: return d->directWriteFallback;
Executed by:
  • tst_QSaveFile
2
241}-
242-
243-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9