Skip to content

Commit

Permalink
feat: Add a status for Symbol-file data events
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Rossetti committed Dec 3, 2018
1 parent 60fde9d commit 13acdd0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
8 changes: 7 additions & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import normalizePath from 'normalize-path'
import { INFOS, BODY_PROGRESS, BODY_SYMBOL_FILE, BODY_HASH, INFOS_SPLIT, END_OF_STAGE_HYPHEN } from './regexp.js'
import { SYMBOL_OPERATIONS } from './references.js'

// Infos about the opertation are given by 7z on the stdout. They can be:
// - colon-seprated: `Creating archive: DirNew/BaseExt.7z`
Expand Down Expand Up @@ -77,7 +78,12 @@ export function matchBodySymbol (stream, line) {
const match = line.match(BODY_SYMBOL_FILE)
if (match) {
match.groups.file = normalizePath(match.groups.file)
return match.groups
const data = {
symbol: match.groups.symbol,
file: normalizePath(match.groups.file),
status: SYMBOL_OPERATIONS[match.groups.symbol]
}
return data
}
return null
}
Expand Down
19 changes: 16 additions & 3 deletions src/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ export const FLAGS = [
{ type: 'bool', api: 'alternateStreamReplace', cli: 'snr' }, // Replace ':' character to '_' character in paths of alternate streams
{ type: 'bool', api: 'deleteFilesAfter', cli: 'sdel' }, // Delete files after compression
{ type: 'bool', api: 'fullyQualifiedPaths', cli: 'spf' }, // Use fully qualified file paths
{ type: 'bool', api: 'hardlinks', cli: 'snh' }, // Store hard links as links (WIM and TAR formats only)
{ type: 'bool', api: 'largePages', cli: 'spl' }, // Set Large Pages mode
{ type: 'bool', api: 'latestTimeStamp', cli: 'stl' }, // Set archive timestamp from the most recently modified file
{ type: 'bool', api: 'noRootDuplication', cli: 'spe' }, // Eliminate duplication of root folder for extract command
{ type: 'bool', api: 'noWildcards', cli: 'spd' }, // Disable wildcard matching for file names
{ type: 'bool', api: 'openFiles', cli: 'ssw' }, // Compress files open for writing
{ type: 'bool', api: 'recursive', cli: 'r' }, // Recurse subdirectories. For `-r0` usage see `raw` @TODO doc usage and tech choice
{ type: 'bool', api: 'hardlinks', cli: 'snh' }, // Store hard links as links (WIM and TAR formats only)
{ type: 'bool', api: 'ntSecurity', cli: 'sni' }, // Store NT security
{ type: 'bool', api: 'openFiles', cli: 'ssw' }, // Compress files open for writing
{ type: 'bool', api: 'recursive', cli: 'r' }, // Recurse subdirectories. For `-r0` usage see `raw`
{ type: 'bool', api: 'symlinks', cli: 'snl' }, // Store symbolic links as links (WIM and TAR formats only)
{ type: 'bool', api: 'techInfo', cli: 'slt' }, // Show technical information
{ type: 'bool', api: 'timeStats', cli: 'bt' },
{ type: 'bool', api: 'toStdout', cli: 'so' }, // Write data to stdout
{ type: 'bool', api: 'yes', cli: 'y' }, // Assume Yes on all queries
{ type: 'boolContext', api: 'alternateStreamStore', cli: 'sns' }, // Store NTFS alternate Streams
Expand All @@ -38,6 +40,7 @@ export const FLAGS = [
{ type: 'stringArray', api: 'method', cli: 'm' }, // Set Compression Method
{ type: 'stringArray', api: 'outputStreams', cli: 'bs' }, // Set output stream for output/error/progress
{ type: 'stringArray', api: 'volumes', cli: 'v' } // Create Volumes
// Advanced
]

export const OPTIONS_DEFAULT = {
Expand All @@ -63,3 +66,13 @@ export const COMMAND_LETTERS = {
test: 't',
update: 'u'
}

// =TU+R.-
export const SYMBOL_OPERATIONS = {
'=': 'renamed',
'T': 'tested',
'U': 'updated',
'R': 'skipped',
'.': 'deleted',
'-': 'extracted'
}
21 changes: 10 additions & 11 deletions test/func/update.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ describe('Functional: update()', function () {
let dataAgg = []
seven.on('data', d => dataAgg.push(d))
seven.on('end', function () {
expect(dataAgg).to.deep.include({ symbol: 'R', file: '#0' })
expect(dataAgg).to.deep.include({ symbol: 'R', file: 'root.md' })
expect(dataAgg).to.deep.include({ symbol: 'R', file: 'root.not' })
expect(dataAgg).to.deep.include({ symbol: '.', file: 'root.txt' })
expect(dataAgg).to.deep.include({ symbol: 'U', file: 'root.txt' })
expect(dataAgg).to.deep.include({ symbol: 'R', file: '#0', status: 'skipped' })
expect(dataAgg).to.deep.include({ symbol: 'R', file: 'root.md', status: 'skipped' })
expect(dataAgg).to.deep.include({ symbol: 'R', file: 'root.not', status: 'skipped' })
expect(dataAgg).to.deep.include({ symbol: '.', file: 'root.txt', status: 'deleted' })
expect(dataAgg).to.deep.include({ symbol: 'U', file: 'root.txt', status: 'updated' })
done()
})
})
Expand All @@ -116,12 +116,11 @@ describe('Functional: update()', function () {
let dataAgg = []
seven.on('data', d => dataAgg.push(d))
seven.on('end', function () {
expect(dataAgg).to.deep.include({ symbol: 'R', file: '#0' })
expect(dataAgg).to.deep.include({ symbol: 'R', file: 'root.not' })
expect(dataAgg).to.deep.include({ symbol: '.', file: 'root.md' })
expect(dataAgg).to.deep.include({ symbol: 'U', file: 'root.md' })
expect(dataAgg).to.deep.include({ symbol: '.', file: 'root.txt' })
expect(dataAgg).to.deep.include({ symbol: 'U', file: 'root.txt' })
expect(dataAgg).to.deep.include({ symbol: 'R', file: '#0', status: 'skipped' })
expect(dataAgg).to.deep.include({ symbol: '.', file: 'root.md', status: 'deleted' })
expect(dataAgg).to.deep.include({ symbol: 'U', file: 'root.md', status: 'updated' })
expect(dataAgg).to.deep.include({ symbol: '.', file: 'root.txt', status: 'deleted' })
expect(dataAgg).to.deep.include({ symbol: 'U', file: 'root.txt', status: 'updated' })
done()
})
})
Expand Down

0 comments on commit 13acdd0

Please sign in to comment.