function findExternalChanges(docs) {

        toReload = [];
        toClose = [];
        editConflicts = [];
        deleteConflicts = [];

        function checkDoc(doc) {
            var result = new $.Deferred();

            // Check file timestamp / existence

            if (doc.isUntitled()) {
                result.resolve();
            } else if (doc.file.donotWatch) { // Some file might not like to be watched!
                result.resolve();
            } else {
                doc.file.stat(function (err, stat) {
                    if (!err) {
                        // Does file's timestamp differ from last sync time on the Document?
                        var fileTime = stat.mtime.getTime();
                        if (fileTime !== doc.diskTimestamp.getTime()) {
                            // If the user has chosen to keep changes that conflict with the
                            // current state of the file on disk, then do nothing. This means
                            // that even if the user later undoes back to clean, we won't
                            // automatically reload the file on window reactivation. We could
                            // make it do that, but it seems better to be consistent with the
                            // deletion case below, where it seems clear that you don't want
                            // to auto-delete the file on window reactivation just because you
                            // undid back to clean.
                            if (doc.keepChangesTime !== fileTime) {
                                if (doc.isDirty) {
                                    editConflicts.push({doc: doc, fileTime: fileTime});
                                } else {
                                    toReload.push(doc);
                                }
                            }
                        }
                        result.resolve();
                    } else {
                        // File has been deleted externally
                        if (err === FileSystemError.NOT_FOUND) {
                            // If the user has chosen to keep changes previously, and the file
                            // has been deleted, then do nothing. Like the case above, this
                            // means that even if the user later undoes back to clean, we won't
                            // then automatically delete the file on window reactivation.
                            // (We use -1 as the "mod time" to indicate that the file didn't
                            // exist, since there's no actual modification time to keep track of
                            // and -1 isn't a valid mod time for a real file.)
                            if (doc.keepChangesTime !== -1) {
                                if (doc.isDirty) {
                                    deleteConflicts.push({doc: doc, fileTime: -1});
                                } else {
                                    toClose.push(doc);
                                }
                            }
                            result.resolve();
                        } else {
                            // Some other error fetching metadata: treat as a real error
                            console.log("Error checking modification status of " + doc.file.fullPath, err);
                            result.reject();
                        }
                    }
                });
            }

            return result.promise();
        }

        // Check all docs in parallel
        // (fail fast b/c we won't continue syncing if there was any error fetching timestamps)
        return Async.doInParallel(docs, checkDoc, true);
    }
function findExternalChanges(docs) {

        toReload = [];
        toClose = [];
        editConflicts = [];
        deleteConflicts = [];

        function checkDoc(doc) {
            var result = new $.Deferred();

            // Check file timestamp / existence

            if (doc.isUntitled()) {
                result.resolve();
            } else if (doc.file.donotWatch) { // Some file might not like to be watched!
                result.resolve();
            } else {
                doc.file.stat(function (err, stat) {
                    if (!err) {
                        // Does file's timestamp differ from last sync time on the Document?
                        var fileTime = stat.mtime.getTime();
                        if (fileTime !== doc.diskTimestamp.getTime()) {
                            // If the user has chosen to keep changes that conflict with the
                            // current state of the file on disk, then do nothing. This means
                            // that even if the user later undoes back to clean, we won't
                            // automatically reload the file on window reactivation. We could
                            // make it do that, but it seems better to be consistent with the
                            // deletion case below, where it seems clear that you don't want
                            // to auto-delete the file on window reactivation just because you
                            // undid back to clean.
                            if (doc.keepChangesTime !== fileTime) {
                                if (doc.isDirty) {
                                    editConflicts.push({doc: doc, fileTime: fileTime});
                                } else {
                                    toReload.push(doc);
                                }
                            }
                        }
                        result.resolve();
                    } else {
                        // File has been deleted externally
                        if (err === FileSystemError.NOT_FOUND) {
                            // If the user has chosen to keep changes previously, and the file
                            // has been deleted, then do nothing. Like the case above, this
                            // means that even if the user later undoes back to clean, we won't
                            // then automatically delete the file on window reactivation.
                            // (We use -1 as the "mod time" to indicate that the file didn't
                            // exist, since there's no actual modification time to keep track of
                            // and -1 isn't a valid mod time for a real file.)
                            if (doc.keepChangesTime !== -1) {
                                if (doc.isDirty) {
                                    deleteConflicts.push({doc: doc, fileTime: -1});
                                } else {
                                    toClose.push(doc);
                                }
                            }
                            result.resolve();
                        } else {
                            // Some other error fetching metadata: treat as a real error
                            console.log("Error checking modification status of " + doc.file.fullPath, err);
                            result.reject();
                        }
                    }
                });
            }

            return result.promise();
        }

        // Check all docs in parallel
        // (fail fast b/c we won't continue syncing if there was any error fetching timestamps)
        return Async.doInParallel(docs, checkDoc, true);
    }
function findExternalChanges ( docs ) { toReload = [ ] ; toClose = [ ] ; editConflicts = [ ] ; deleteConflicts = [ ] ; function checkDoc ( doc ) { var result = new $ . Deferred ( ) ; // Check file timestamp / existence if ( doc . isUntitled ( ) ) { result . resolve ( ) ; } else if ( doc . file . donotWatch ) { // Some file might not like to be watched! result . resolve ( ) ; } else { doc . file . stat ( function ( err , stat ) { if ( ! err ) { // Does file's timestamp differ from last sync time on the Document? var fileTime = stat . mtime . getTime ( ) ; if ( fileTime !== doc . diskTimestamp . getTime ( ) ) { // If the user has chosen to keep changes that conflict with the // current state of the file on disk, then do nothing. This means // that even if the user later undoes back to clean, we won't // automatically reload the file on window reactivation. We could // make it do that, but it seems better to be consistent with the // deletion case below, where it seems clear that you don't want // to auto-delete the file on window reactivation just because you // undid back to clean. if ( doc . keepChangesTime !== fileTime ) { if ( doc . isDirty ) { editConflicts . push ( { doc : doc , fileTime : fileTime } ) ; } else { toReload . push ( doc ) ; } } } result . resolve ( ) ; } else { // File has been deleted externally if ( err === FileSystemError . NOT_FOUND ) { // If the user has chosen to keep changes previously, and the file // has been deleted, then do nothing. Like the case above, this // means that even if the user later undoes back to clean, we won't // then automatically delete the file on window reactivation. // (We use -1 as the "mod time" to indicate that the file didn't // exist, since there's no actual modification time to keep track of // and -1 isn't a valid mod time for a real file.) if ( doc . keepChangesTime !== - 1 ) { if ( doc . isDirty ) { deleteConflicts . push ( { doc : doc , fileTime : - 1 } ) ; } else { toClose . push ( doc ) ; } } result . resolve ( ) ; } else { // Some other error fetching metadata: treat as a real error console . log ( "Error checking modification status of " + doc . file . fullPath , err ) ; result . reject ( ) ; } } } ) ; } return result . promise ( ) ; } // Check all docs in parallel // (fail fast b/c we won't continue syncing if there was any error fetching timestamps) return Async . doInParallel ( docs , checkDoc , true ) ; }
Scans all the given Documents for changes on disk, and sorts them into four buckets,
populating the corresponding arrays:
toReload        - changed on disk; unchanged within Brackets
toClose         - deleted on disk; unchanged within Brackets
editConflicts   - changed on disk; also dirty in Brackets
deleteConflicts - deleted on disk; also dirty in Brackets

@param {!Array.<Document>} docs
@return {$.Promise}  Resolved when all scanning done, or rejected immediately if there's any
error while reading file timestamps. Errors are logged but no UI is shown.
Scans all the given Documents for changes on disk and sorts them into four buckets populating the corresponding arrays : toReload - changed on disk ; unchanged within Brackets toClose - deleted on disk ; unchanged within Brackets editConflicts - changed on disk ; also dirty in Brackets deleteConflicts - deleted on disk ; also dirty in Brackets
Find external changes