lib/fs.js
function _zero(_arg, _cb) {
        if (!_arg.create) {
            _cb();
            return;
        }

        // We need to stub this out now since we won't write the file to manta
        // until writeback runs on this file.
        var now = new Date().toUTCString();
        var info = {
            extension: 'bin',
            type: 'application/octet-stream',
            parent: path.dirname(p),
            size: 0,
            headers: {
                'last-modified': now
            }
        };

        var opts = {};
        if (_arg.exclusive) {
            // exclusive applies only to the local file in the cache
            opts.flag = 'wx';
        } else {
            opts.flag = 'w';
        }

        self._stat(p, info, function (s_err, stats) {
            if (s_err) {
                _cb(s_err);
                return;
            }

            fs.writeFile(stats._cacheFile, new Buffer(0), opts, function (err) {
                if (err) {
                    _cb(err);
                    return;
                }

                // mark file as dirty in the cache
                self.cache.dirty(p, stats._fhandle, function (d_err) {
                    if (d_err) {
                        log.warn(d_err, 'dirty(%s): failed', p);
                        _cb(d_err);
                    } else {
                        self.cache.add_to_pdir(p, _cb);
                    }
                });
            });
        });
    }
function _zero(_arg, _cb) {
        if (!_arg.create) {
            _cb();
            return;
        }

        // We need to stub this out now since we won't write the file to manta
        // until writeback runs on this file.
        var now = new Date().toUTCString();
        var info = {
            extension: 'bin',
            type: 'application/octet-stream',
            parent: path.dirname(p),
            size: 0,
            headers: {
                'last-modified': now
            }
        };

        var opts = {};
        if (_arg.exclusive) {
            // exclusive applies only to the local file in the cache
            opts.flag = 'wx';
        } else {
            opts.flag = 'w';
        }

        self._stat(p, info, function (s_err, stats) {
            if (s_err) {
                _cb(s_err);
                return;
            }

            fs.writeFile(stats._cacheFile, new Buffer(0), opts, function (err) {
                if (err) {
                    _cb(err);
                    return;
                }

                // mark file as dirty in the cache
                self.cache.dirty(p, stats._fhandle, function (d_err) {
                    if (d_err) {
                        log.warn(d_err, 'dirty(%s): failed', p);
                        _cb(d_err);
                    } else {
                        self.cache.add_to_pdir(p, _cb);
                    }
                });
            });
        });
    }
function _zero ( _arg , _cb ) { if ( ! _arg . create ) { _cb ( ) ; return ; } // We need to stub this out now since we won't write the file to manta // until writeback runs on this file. var now = new Date ( ) . toUTCString ( ) ; var info = { extension : 'bin' , type : 'application/octet-stream' , parent : path . dirname ( p ) , size : 0 , headers : { 'last-modified' : now } } ; var opts = { } ; if ( _arg . exclusive ) { // exclusive applies only to the local file in the cache opts . flag = 'wx' ; } else { opts . flag = 'w' ; } self . _stat ( p , info , function ( s_err , stats ) { if ( s_err ) { _cb ( s_err ) ; return ; } fs . writeFile ( stats . _cacheFile , new Buffer ( 0 ) , opts , function ( err ) { if ( err ) { _cb ( err ) ; return ; } // mark file as dirty in the cache self . cache . dirty ( p , stats . _fhandle , function ( d_err ) { if ( d_err ) { log . warn ( d_err , 'dirty(%s): failed' , p ) ; _cb ( d_err ) ; } else { self . cache . add_to_pdir ( p , _cb ) ; } } ) ; } ) ; } ) ; }
When creating use _stat to save the zero-size new file info into the cache and create an empty local file.
When creating use _stat to save the zero - size new file info into the cache and create an empty local file .