Skip to content

Commit

Permalink
Added 'utils.unwatchFile()' function to fix #117
Browse files Browse the repository at this point in the history
  • Loading branch information
walterhiggins committed Feb 11, 2014
1 parent 3c7d3a2 commit 2e4516b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/API-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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...
Expand Down
23 changes: 21 additions & 2 deletions src/main/js/modules/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
var File = java.io.File;
/************************************************************************
## Utilities Module
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/main/js/plugins/classroom/classroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit 2e4516b

Please sign in to comment.