harrisiirak / webhdfs

Node.js WebHDFS REST API client
MIT License
89 stars 42 forks source link

unable to delete a folder which is not empty #27

Open aakashkumar667 opened 6 years ago

aakashkumar667 commented 6 years ago

hi, I am unable to delete a folder which is not empty and getting the following error.

{"RemoteException":{"exception":"PathIsNotEmptyDirectoryException","javaClassName":"org.apache.hadoop.fs.PathIsNotEmptyDirectoryException","message":"`/aakash is non empty': Directory is not empty"}}

SavePointSam commented 6 years ago

In order to delete a directory that has content you need to pass the recursive option as well as a callback for handling errors like so:

import WebHDFS from 'webhdfs';

const client = WebHDFS.createClient({
  host: 'example.dev.company.com',
  port: 8080,
  path: '/',
});

const deleteDirectoryWithContent = (directoryPath) => 
  client.unlink(directoryPath, true, (error) => {
    if (error) throw error;
  });