kylefarris / clamscan

A robust ClamAV virus scanning library supporting scanning files, directories, and streams with local sockets, local/remote TCP, and local clamscan/clamdscan binaries (with failover).
MIT License
236 stars 69 forks source link

Using clamdscan with scan_recursively not working as expected #12

Closed taietel closed 9 years ago

taietel commented 9 years ago

I think that the issue with clamdscan and scan_recursively is not entirely fixed or I didn't understood right what needs to output. Now it works, but only shows the files that are directly in that folder, the ones that are in subfolders are not shown, they are not even scanned.

kylefarris commented 9 years ago

@taietel Yeah, I think you may have a slight misunderstanding here. With scan_recursively set to false, the module will not scan sub-directories. scan_recursively means to "scan the specified path _and_ all subpaths". Obviously, if you set that option to false, it will not scan all sub-paths. On UNIX, if you run clamdscan manually in the shell, it does this by default but does not give any feedback on a file-by-file basis.

I guess it comes down to this... if you want to run a deep scan on a folder and all it's sub-folders (apparently to a limit at the moment) and get an array of all the good and bad files while using the clamdscan option as your scanner, you have specify scan_recursively: true and you must supply a you must supply a per-file callback (even if it does nothing).

Here's an example:

var clamscan = require('clamscan')({
    scan_recursively: true
});

clamscan.scan_dir('/path/of/folder/to/scan', function(err, good_files, bad_files) {
    if (!err) {
        if (bad_files.length > 0) {
            console.log("Your directory was infected.");
            console.log("BadFiles: ", good_files);
        } else {
            console.log("Your directory and sub-directories are clean!");
        }
    }
}, function(err, file, is_infected) {
    // You can just leave this part blank if you want.
});

I've just tested this and it works as expected.

taietel commented 9 years ago

Ok, thanks for clearing that out for me, I used the solution from your example, since yesterday, and it works.