Windows: stop storage service during write

The moment we write the block containing the partition table
Windows services will start accessing the SD card and write data
to "System volume information" folder.

If others are writing to disk concurrently this may or may not
affect our ability to eject the drive.
Stop StorSvc temporarily between us writing the partition table
(saved for last) and ejecting the SD card, just in case.

Ref #75
This commit is contained in:
Floris Bos 2020-07-03 21:11:34 +02:00
parent 19bfc8eacb
commit 5f42c7d7cb

View file

@ -585,6 +585,14 @@ void DownloadThread::_writeComplete()
emit finalizing(); emit finalizing();
#ifdef Q_OS_WIN
// Temporarily stop storage services to prevent \[System Volume Information]\WPSettings.dat being created
QProcess p1;
QStringList args = {"stop", "StorSvc"};
qDebug() << "Stopping storage services";
p1.execute("net", args);
#endif
if (_firstBlock) if (_firstBlock)
{ {
qDebug() << "Writing first block (which we skipped at first)"; qDebug() << "Writing first block (which we skipped at first)";
@ -610,6 +618,13 @@ void DownloadThread::_writeComplete()
#endif #endif
eject_disk(_filename.constData()); eject_disk(_filename.constData());
#ifdef Q_OS_WIN
QStringList args = {"start", "StorSvc"};
QProcess *p2 = new QProcess(this);
qDebug() << "Restarting storage services";
p2->startDetached("net", args);
#endif
emit success(); emit success();
} }