update.js 842 B

123456789101112131415161718192021222324252627282930313233343536
  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. if (opt.gzip)
  11. throw new TypeError('cannot append to compressed archives')
  12. if (!files || !Array.isArray(files) || !files.length)
  13. throw new TypeError('no files or directories specified')
  14. files = Array.from(files)
  15. mtimeFilter(opt)
  16. return r(opt, files, cb)
  17. }
  18. const mtimeFilter = opt => {
  19. const filter = opt.filter
  20. if (!opt.mtimeCache)
  21. opt.mtimeCache = new Map()
  22. opt.filter = filter ? (path, stat) =>
  23. filter(path, stat) && !(opt.mtimeCache.get(path) > stat.mtime)
  24. : (path, stat) => !(opt.mtimeCache.get(path) > stat.mtime)
  25. }