Commit 6c5d3313 authored by Tatsuhisa Yamaguchi's avatar Tatsuhisa Yamaguchi Committed by Commit Bot

Create zip file in temporary storage.

This will avoid exposing in-progress zip file to the destination folder.
It will resolve the issues like:
- the zip file is synced to Drive with incomplete state, having multiple
  revisions
- when cancelling zip packing, the file appears in the trash of Drive

Bug: 714579,785096,785093,785086,797873
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I0b32515d5e896d87e1dee499f1eea40dd7a481f0
Reviewed-on: https://chromium-review.googlesource.com/844442
Commit-Queue: Tatsuhisa Yamaguchi <yamaguchi@chromium.org>
Reviewed-by: default avatarNaoki Fukino <fukino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547428}
parent bf8191d0
......@@ -880,4 +880,55 @@ unpacker.app = {
else
unpacker.app.onLaunchedWithUnpack(launchData, opt_onSuccess, opt_onError);
},
/**
* Clean all temporary files inside the work directory.
* Those files are usually moved to the destination directory when finished
* or removed when any error happened, but might be left there when the
* extension was aborted by runtime errors or system shutdown.
*/
cleanWorkDirectory: function() {
return new Promise(
webkitRequestFileSystem.bind(null, TEMPORARY, 0 /* size */))
.then((fs) => new Promise(function(resolve, reject) {
const reader = fs.root.createReader();
let allEntries = [];
function scanEntries() {
reader.readEntries((entries) => {
if (entries.length == 0) {
resolve(allEntries);
return;
}
Array.prototype.push.apply(allEntries, entries);
scanEntries();
});
}
scanEntries();
}))
.then((allEntries) => {
allEntries.forEach((entry) => {
if (entry.isDirectory) {
entry.removeRecursively(
function() {
console.info(
'Found directory. ',
'Perhaps the extension had exited abnormally.', entry);
},
function() {
console.error('Failed to remove a directory:', entry);
});
} else {
entry.remove(
function() {
console.info(
'Found a temporary file. ',
'Perhaps the extension had exited abnormally.', entry);
},
function() {
console.error('Failed to remove a temporary file:', entry);
});
}
});
});
}
};
......@@ -30,3 +30,7 @@ unpacker.app.loadNaclModule('module.nmf', 'application/x-pnacl');
// Load translations
unpacker.app.loadStringData();
// Clean all temporary files inside the work directory, just in case the
// extension aborted previously without removing ones.
unpacker.app.cleanWorkDirectory();
......@@ -23,7 +23,7 @@
]
},
"notifications",
"storage"
"unlimitedStorage"
],
"file_system_provider_capabilities": {
"multipleMounts": true,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment