fix: index filenames with utf-8 characters on Windows

Fixes #184
pull/231/head
Romain 3 years ago
parent 293cbf8469
commit f3571718ce

@ -1,4 +1,5 @@
const childProcess = require('child_process')
const trace = require('debug')('thumbsup:trace')
const debug = require('debug')('thumbsup:debug')
const error = require('debug')('thumbsup:error')
const es = require('event-stream')
@ -18,6 +19,8 @@ exports.parse = (rootFolder, filePaths) => {
'%+.6f', // lat/long = float values
'-struct', // preserve XMP structure
'-json', // JSON output
'-charset', // allow UTF8 filenames
'filename=utf8', // allow UTF8 filenames
'-@', // specify more arguments separately
'-' // read arguments from standard in
]
@ -25,7 +28,7 @@ exports.parse = (rootFolder, filePaths) => {
// create a new <exiftool> child process
const child = childProcess.spawn('exiftool', args, {
cwd: rootFolder,
stdio: [ 'pipe', 'pipe', 'ignore' ]
stdio: [ 'pipe', 'pipe', 'pipe' ]
})
child.on('error', (err) => {
error(`Error: please verify that <exiftool> is installed on your system`)
@ -35,6 +38,10 @@ exports.parse = (rootFolder, filePaths) => {
debug(`Exiftool exited with code ${code}`)
})
child.stderr.on('data', chunk => {
trace('Exiftool output:', chunk.toString())
})
// write all files to <stdin>
// exiftool will only start processing after <stdin> is closed
const allFiles = filePaths.join('\n')

@ -28,6 +28,22 @@ describe('exiftool', function () {
})
})
it('can process files with UTF8 names', (done) => {
// generate some photos in a temp folder
const structure = {
'photoà.jpg': fixtures.fromDisk('photo.jpg')
}
const tmpdir = fixtures.createTempStructure(structure)
const processed = []
const stream = exiftool.parse(tmpdir, Object.keys(structure))
stream.on('data', entry => {
processed.push(entry.SourceFile)
}).on('end', () => {
should(processed).eql(['photoà.jpg'])
done()
})
})
it('can process badly encoded fields', (done) => {
// here we test with an XMP file because it's easier to see what's wrong
// but the problem will more likely be with a badly encoded XMP section inside a JPG file

Loading…
Cancel
Save