11cb0ef41Sopenharmony_ci'use strict' 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// tar -u 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst hlo = require('./high-level-opt.js') 61cb0ef41Sopenharmony_ciconst r = require('./replace.js') 71cb0ef41Sopenharmony_ci// just call tar.r with the filter and mtimeCache 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cimodule.exports = (opt_, files, cb) => { 101cb0ef41Sopenharmony_ci const opt = hlo(opt_) 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci if (!opt.file) { 131cb0ef41Sopenharmony_ci throw new TypeError('file is required') 141cb0ef41Sopenharmony_ci } 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci if (opt.gzip || opt.brotli || opt.file.endsWith('.br') || opt.file.endsWith('.tbr')) { 171cb0ef41Sopenharmony_ci throw new TypeError('cannot append to compressed archives') 181cb0ef41Sopenharmony_ci } 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci if (!files || !Array.isArray(files) || !files.length) { 211cb0ef41Sopenharmony_ci throw new TypeError('no files or directories specified') 221cb0ef41Sopenharmony_ci } 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci files = Array.from(files) 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci mtimeFilter(opt) 271cb0ef41Sopenharmony_ci return r(opt, files, cb) 281cb0ef41Sopenharmony_ci} 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciconst mtimeFilter = opt => { 311cb0ef41Sopenharmony_ci const filter = opt.filter 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci if (!opt.mtimeCache) { 341cb0ef41Sopenharmony_ci opt.mtimeCache = new Map() 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci opt.filter = filter ? (path, stat) => 381cb0ef41Sopenharmony_ci filter(path, stat) && !(opt.mtimeCache.get(path) > stat.mtime) 391cb0ef41Sopenharmony_ci : (path, stat) => !(opt.mtimeCache.get(path) > stat.mtime) 401cb0ef41Sopenharmony_ci} 41