Exemplo n.º 1
0
            fs.copy(src, dest, function (err) {
                if(err) return reject(err);

                var retryCount = 0;
                var existsCallback = function(exists){
                    if(exists){
                        fs.chmod(dest, stats.mode, function(err){
                            // ignore error
                            if (err) {
                                _event.emit('log', 'error: ' + err);
                                _event.emit('log', 'chmod ' + stats.mode + ' on ' + dest + ' failed after copying, ignoring');
                            }

                            resolve();
                        });
                    } else if (retryCount++ < 2) {
                        // This is antipattern!!!
                        // Callback should be called when the copy is finished!!!!
                        setTimeout(function(){
                            fs.exists(dest, existsCallback);
                        }, 1000);
                    } else {
                        reject(new Error("Copied file (" + dest + ") doesn't exist in destination after copying"));
                    }
                };

                fs.exists(dest, existsCallback);
            });
Exemplo n.º 2
0
 setTimeout(function(){
     fs.exists(dest, existsCallback);
 }, 1000);