Added 'utils.unwatchFile()' function to fix #117
This commit is contained in:
parent
3c7d3a2bb4
commit
2e4516bf69
3 changed files with 37 additions and 2 deletions
|
@ -70,6 +70,7 @@ Walter Higgins
|
|||
* [utils.find() function](#utilsfind-function)
|
||||
* [utils.serverAddress() function](#utilsserveraddress-function)
|
||||
* [utils.watchFile() function](#utilswatchfile-function)
|
||||
* [utils.unwatchFile() function](#utilsunwatchfile-function)
|
||||
* [Drone Plugin](#drone-plugin)
|
||||
* [TLDNR; (Just read this if you're impatient)](#tldnr-just-read-this-if-youre-impatient)
|
||||
* [Constructing a Drone Object](#constructing-a-drone-object)
|
||||
|
@ -1368,6 +1369,16 @@ utils.watchFile( 'test.txt', function( file ) {
|
|||
console.log( file + ' has changed');
|
||||
});
|
||||
```
|
||||
### utils.unwatchFile() function
|
||||
|
||||
Removes a file from the watch list.
|
||||
|
||||
#### Example
|
||||
```javascript
|
||||
var utils = require('utils');
|
||||
utils.unwatchFile( 'test.txt');
|
||||
```
|
||||
|
||||
## Drone Plugin
|
||||
|
||||
The Drone is a convenience class for building. It can be used for...
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
var File = java.io.File;
|
||||
/************************************************************************
|
||||
## Utilities Module
|
||||
|
||||
|
@ -440,7 +441,7 @@ var jsFiles = utils.find('./', function(dir,name){
|
|||
exports.find = function( dir , filter ) {
|
||||
var result = [];
|
||||
var recurse = function( dir, store ) {
|
||||
var files, dirfile = new java.io.File( dir );
|
||||
var files, dirfile = new File( dir );
|
||||
|
||||
if ( typeof filter == 'undefined' ) {
|
||||
files = dirfile.list();
|
||||
|
@ -514,7 +515,6 @@ utils.watchFile( 'test.txt', function( file ) {
|
|||
***/
|
||||
var filesWatched = {};
|
||||
exports.watchFile = function( file, callback ) {
|
||||
var File = java.io.File;
|
||||
if ( typeof file == 'string' ) {
|
||||
file = new File(file);
|
||||
}
|
||||
|
@ -523,6 +523,25 @@ exports.watchFile = function( file, callback ) {
|
|||
lastModified: file.lastModified()
|
||||
};
|
||||
};
|
||||
/************************************************************************
|
||||
### utils.unwatchFile() function
|
||||
|
||||
Removes a file from the watch list.
|
||||
|
||||
#### Example
|
||||
```javascript
|
||||
var utils = require('utils');
|
||||
utils.unwatchFile( 'test.txt');
|
||||
```
|
||||
|
||||
***/
|
||||
exports.unwatchFile = function( file, callback ) {
|
||||
if ( typeof file == 'string' ) {
|
||||
file = new File(file);
|
||||
}
|
||||
delete filesWatched[file.canonicalPath];
|
||||
};
|
||||
|
||||
function fileWatcher() {
|
||||
for (var file in filesWatched) {
|
||||
var fileObject = new File(file);
|
||||
|
|
|
@ -3,6 +3,7 @@ var utils = require('utils'),
|
|||
logger = __plugin.logger,
|
||||
foreach = utils.foreach,
|
||||
watchFile = utils.watchFile,
|
||||
unwatchFile = utils.unwatchFile,
|
||||
playersDir = __dirname + '/../../players/',
|
||||
serverAddress = utils.serverAddress();
|
||||
|
||||
|
@ -100,6 +101,10 @@ function revokeScripting ( player ) {
|
|||
}
|
||||
}
|
||||
});
|
||||
var playerName = '' + player.name;
|
||||
playerName = playerName.replace(/[^a-zA-Z0-9_\-]/g,'');
|
||||
var playerDir = new File( playersDir + playerName );
|
||||
unwatchFile( playerDir );
|
||||
}
|
||||
|
||||
function grantScripting( player ) {
|
||||
|
|
Reference in a new issue