From f29aa16683f869ed268e1545ef314c4cf750ed1f Mon Sep 17 00:00:00 2001 From: nao-pon Date: Sat, 12 Jun 2021 00:46:08 +0900 Subject: [PATCH] [cmd:extract] fix #3252 for checking the existence of existing files --- js/commands/extract.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/js/commands/extract.js b/js/commands/extract.js index 87fb033b30..dc5a35d7ac 100644 --- a/js/commands/extract.js +++ b/js/commands/extract.js @@ -10,8 +10,10 @@ elFinder.prototype.commands.extract = function() { fm = self.fm, mimes = [], filter = function(files) { + var fres = true; return $.grep(files, function(file) { - return file.read && $.inArray(file.mime, mimes) !== -1 ? true : false; + fres = fres && file.read && $.inArray(file.mime, mimes) !== -1 ? true : false; + return fres; }); }; @@ -31,9 +33,20 @@ elFinder.prototype.commands.extract = function() { this.getstate = function(select) { var sel = this.files(select), - cnt = sel.length; - - return cnt && this.fm.cwd().write && filter(sel).length == cnt ? 0 : -1; + cnt = sel.length, + cwdHash, cwdChk; + if (!cnt || filter(sel).length != cnt) { + return -1; + } else if (fm.searchStatus.state > 0) { + cwdHash = this.fm.cwd().hash; + $.each(sel, function(i, file) { + cwdChk = (file.phash === cwdHash); + return cwdChk; + }); + return cwdChk? 0 : -1; + } else { + return this.fm.cwd().write? 0 : -1; + } }; this.exec = function(hashes, opts) { @@ -42,17 +55,19 @@ elFinder.prototype.commands.extract = function() { cnt = files.length, makedir = opts && opts.makedir ? 1 : 0, i, error, - decision; + decision, + + overwriteAll = false, + omitAll = false, + mkdirAll = 0, + siblings = fm.files(files[0].phash), - var overwriteAll = false; - var omitAll = false; - var mkdirAll = 0; + names = [], + map = {}; - var names = $.map(fm.files(hashes), function(file) { return file.name; }); - var map = {}; - $.grep(fm.files(hashes), function(file) { + $.each(siblings, function(id, file) { map[file.name] = file; - return false; + names.push(file.name); }); var decide = function(decision) {