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