@@ -108,7 +108,8 @@ const WS_COMMAND = {
108108 READ_BIN_FILE : "readBinFile" ,
109109 WRITE_BIN_FILE : "writeBinFile" ,
110110 MKDIR : "mkdir" ,
111- RENAME : "rename"
111+ RENAME : "rename" ,
112+ UNLINK : "unlink"
112113} ;
113114
114115const LARGE_DATA_THRESHOLD = 2 * 1024 * 1024 ; // 2MB
@@ -247,7 +248,7 @@ function _mkdir(ws, metadata) {
247248 fs . mkdir ( fullPath , { recursive, mode} )
248249 . then ( ( ) => {
249250 _sendResponse ( ws , metadata ) ;
250- } ) . catch ( ( err ) => _reportError ( ws , metadata , err , `Failed to write file at path ${ fullPath } ` ) ) ;
251+ } ) . catch ( ( err ) => _reportError ( ws , metadata , err , `Failed to mkdir at path ${ fullPath } ` ) ) ;
251252}
252253
253254function _rename ( ws , metadata ) {
@@ -256,7 +257,15 @@ function _rename(ws, metadata) {
256257 fs . rename ( oldPath , newPath )
257258 . then ( ( ) => {
258259 _sendResponse ( ws , metadata ) ;
259- } ) . catch ( ( err ) => _reportError ( ws , metadata , err , `Failed to write file at path ${ fullPath } ` ) ) ;
260+ } ) . catch ( ( err ) => _reportError ( ws , metadata , err , `Failed to rename file at path ${ oldPath } to ${ newPath } ` ) ) ;
261+ }
262+
263+ function _unlink ( ws , metadata ) {
264+ const fullPath = metadata . data . path ;
265+ fs . rm ( fullPath , { recursive : true } )
266+ . then ( ( ) => {
267+ _sendResponse ( ws , metadata ) ;
268+ } ) . catch ( ( err ) => _reportError ( ws , metadata , err , `Failed to unlink path ${ fullPath } ` ) ) ;
260269}
261270
262271function processWSCommand ( ws , metadata , dataBuffer ) {
@@ -289,6 +298,9 @@ function processWSCommand(ws, metadata, dataBuffer) {
289298 case WS_COMMAND . RENAME :
290299 _rename ( ws , metadata ) ;
291300 return ;
301+ case WS_COMMAND . UNLINK :
302+ _unlink ( ws , metadata ) ;
303+ return ;
292304 case WS_COMMAND . LARGE_DATA_SOCKET_ANNOUNCE :
293305 console . log ( "Large Data Transfer Socket established, socket Group: " , metadata . socketGroupID ) ;
294306 ws . isLargeData = true ;
0 commit comments