Don’t index media from Synology thumbnail folders (@eaDir) nor folders starting with “.”

exif-summary
Romain 7 years ago
parent ac520d40ad
commit cbf8a1f3b4

@ -66,7 +66,9 @@
"public/**"
],
"globals": [
"after",
"afterEach",
"before",
"beforeEach",
"describe",
"xdescribe",

@ -12,8 +12,8 @@ const MEDIA_GLOB = '**/*.{' + PHOTO_EXT.join(',') + ',' + VIDEO_EXT.join(',') +
exports.find = function (rootFolder, callback) {
const entries = {}
const stream = readdir.readdirStreamStat(rootFolder, {
filter: entry => micromatch(entry.path, MEDIA_GLOB, {nocase: true}).length !== 0,
deep: stats => stats.path.charAt(0) !== '.',
filter: entry => micromatch.match(entry.path, MEDIA_GLOB, {nocase: true}).length !== 0,
deep: stats => canTraverse(stats.path),
basePath: '',
sep: '/'
})
@ -22,6 +22,17 @@ exports.find = function (rootFolder, callback) {
stream.on('end', () => callback(null, entries))
}
function canTraverse (folder) {
// ignore folders starting with '.'
// and thumbnail folders from Synology NAS
// it's better to skip them in the "traverse phase" than to remove them at the end
const match = micromatch.match(folder, '**/**', {
dot: false,
ignore: ['**/@eaDir']
})
return match.length > 0
}
function isEnoentCodeError (err) {
return err.code === 'ENOENT'
}

@ -10,7 +10,9 @@ const files = readdir.sync(folder, {
deep: true
})
describe('exiftool', () => {
describe('exiftool', function () {
this.slow(1000)
this.timeout(1000)
it('processes all files', (done) => {
const processed = []
const stream = exiftool.parse(folder, files)

@ -1,4 +1,4 @@
const mock = require('mock-fs')
const glob = require('../../../src/components/index/glob')
const should = require('should/as-function')
@ -6,6 +6,12 @@ describe('Index: glob', function () {
this.slow(500)
this.timeout(500)
// we require "mock-fs" inside the tests, otherwise it also affects other tests
var mock = null
before(() => {
mock = require('mock-fs')
})
afterEach(() => {
mock.restore()
})
@ -56,16 +62,34 @@ describe('Index: glob', function () {
})
})
it('ignores folders starting with a dot', (done) => {
it('ignores any folder starting with a dot', (done) => {
mock({
'media/IMG_0001.JPG': '...',
'media/.git/IMG_0002.JPG': '...'
'media/IMG_0001.jpg': '...',
'media/.git/IMG_0002.jpg': '...',
'media/nested/.private/IMG_0003.jpg': '...',
'media/just/a.dot/IMG_0004.jpg': '...'
})
glob.find('media', (err, map) => {
if (err) return done(err)
const keys = Object.keys(map).sort()
should(keys).eql([
'IMG_0001.JPG'
'IMG_0001.jpg',
'just/a.dot/IMG_0004.jpg'
])
done()
})
})
it('ignores folders called @eaDir (Synology thumbnail folders)', (done) => {
mock({
'media/holidays/IMG_0001.jpg': '...',
'media/holidays/@eaDir/IMG_0001.jpg': '...'
})
glob.find('media', (err, map) => {
if (err) return done(err)
const keys = Object.keys(map).sort()
should(keys).eql([
'holidays/IMG_0001.jpg'
])
done()
})

@ -5,6 +5,7 @@ const should = require('should/as-function')
describe('Index', function () {
this.slow(1000)
this.timeout(1000)
it('indexes the fixtures', (done) => {
const index = new Index('thumbsup.db')
const fixtures = path.join(__dirname, '..', '..', '..', 'fixtures')

Loading…
Cancel
Save