Add path exclusion

This commit is contained in:
brunosimon
2016-11-20 22:40:37 +01:00
parent fadf6aba11
commit f686b16daa
5 changed files with 42 additions and 4 deletions
+28 -1
View File
@@ -7,7 +7,8 @@ let chokidar = require( 'chokidar' ),
ip = require( 'ip' ),
socket_io_client = require( 'socket.io-client' ),
fs = require( 'fs' ),
mime = require( 'mime' )
mime = require( 'mime' ),
minimatch = require( 'minimatch' )
/**
* Watcher class
@@ -104,9 +105,22 @@ class Watcher
file.can_read = false;
}
// Test exclusion
for( let _exclude_key in this.options.exclude )
{
// Set up
let _exclude = this.options.exclude[ _exclude_key ],
relative_path = _path.replace( process.cwd() + '/', '' )
// Match excluded path
if( minimatch( relative_path, _exclude ) )
return;
}
// Retrieve stats
fs.stat( _path, ( error, stats ) =>
{
// Max file size
if( stats.size > this.options.max_file_size )
file.can_read = false
@@ -145,9 +159,22 @@ class Watcher
file.can_read = false;
}
// Test exclusion
for( let _exclude_key in this.options.exclude )
{
// Set up
let _exclude = this.options.exclude[ _exclude_key ],
relative_path = _path.replace( process.cwd() + '/', '' )
// Match excluded path
if( minimatch( relative_path, _exclude ) )
return;
}
// Retrieve stats
fs.stat( _path, ( error, stats ) =>
{
// Test max file size
if( stats.size > this.options.max_file_size )
file.can_read = false