/**
 * Write a readonly file.
 * @function lib.file.writeReadonlyFile
 * @param {string} filename - Filename to write.
 * @param {string} content - File content to write.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 *
 */
var fs = require('fs');

exports = module.exports = function (filename, content, callback) {
    if (!callback) callback = new Function;
    exports._forceUnlink(filename, function (err) {
        if (err) {
            callback(err);
            return;
        }
        exports._writeFile(filename, content, function (err) {
            if (err) {
                callback(err);
                return;
            }
            fs.chmod(filename, '444', function (err) {
                callback(err);
            });
        });
    });
};
exports._forceUnlink = require('./force_unlink');
exports._writeFile = fs.writeFile;