BenoitGauthier / diskinfo

nodejs module to get disk information
MIT License
10 stars 13 forks source link

Duplicated entries after multiple calls on Windows #1

Open ghost opened 9 years ago

ghost commented 9 years ago

When i call getDrives multiple times (on Windows) i get duplicated entries inside that array. The cause seems to be multiple calls of getDrives, before one call ends.

Best regards

Michael

ghost commented 9 years ago

I Build a wrapper around your module to prevent this behaviour:

var diskinfo = require("diskinfo");

filesystem = { distinct: function (array) { var result = []; array.forEach(function (entry) { var same = result.filter(function (value) { return value.mounted === entry.mounted; });

        if(same.length <= 0)
            result.push(entry);
    });
    return result;
},
search: function (onSuccess, onError) {
    diskinfo.getDrives(function(error, disks){
        if (error)
            return onError(error);

        var result = filesystem.distinct(disks);
        return onSuccess(result);
    });
}

};

module.exports = filesystem;

joaosp commented 9 years ago

if you leave this running for a long time with that wrapper you will have a nice memory leak

I've suggested a change by commit to fix this

ghostclearsky commented 3 years ago

it's a bug. function getDrives should reset aDrives; at getDrives entry insert one line: aDrives = [];

getDrives函数存在bug,应该在函数入口处重置aDrives变量为空数组:aDrives = [];