You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

update.js 937B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict'
  2. // tar -u
  3. const hlo = require('./high-level-opt.js')
  4. const r = require('./replace.js')
  5. // just call tar.r with the filter and mtimeCache
  6. module.exports = (opt_, files, cb) => {
  7. const opt = hlo(opt_)
  8. if (!opt.file) {
  9. throw new TypeError('file is required')
  10. }
  11. if (opt.gzip || opt.brotli || opt.file.endsWith('.br') || opt.file.endsWith('.tbr')) {
  12. throw new TypeError('cannot append to compressed archives')
  13. }
  14. if (!files || !Array.isArray(files) || !files.length) {
  15. throw new TypeError('no files or directories specified')
  16. }
  17. files = Array.from(files)
  18. mtimeFilter(opt)
  19. return r(opt, files, cb)
  20. }
  21. const mtimeFilter = opt => {
  22. const filter = opt.filter
  23. if (!opt.mtimeCache) {
  24. opt.mtimeCache = new Map()
  25. }
  26. opt.filter = filter ? (path, stat) =>
  27. filter(path, stat) && !(opt.mtimeCache.get(path) > stat.mtime)
  28. : (path, stat) => !(opt.mtimeCache.get(path) > stat.mtime)
  29. }