Commit deferred writes to file.
323303
def sync(self):
        """"""
        for key_hash, obj in six.iteritems(self._cache):
            # Objects are checked for expiration in __getitem__,
            # but we can check here to avoid unnecessary writes.
            if not obj.has_expired():
                file_path = self._path_for_hash(key_hash)
                with open(str(file_path), self._write_mode) as f:
                    obj.dump(f)
1291589
def write(dump)
      with_flock(File::LOCK_EX) do
        @fd.write(dump)
        # Flush to make sure the file is really updated
        @fd.flush
      end
      @pos = @fd.pos if @pos && @fd.pos == @pos + dump.bytesize
    end
965782
def _connect_deferred(self, deferred):
        
        self._deferred = deferred

        # Because we use __del__, we need to make sure there are no cycles
        # involving this object, which is why we use a weakref:
        def put(result, eventual=weakref.ref(self)):
            eventual = eventual()
            if eventual:
                eventual._set_result(result)
            else:
                err(result, "Unhandled error in EventualResult")

        deferred.addBoth(put)
971228
def _pre_commit(files, options):
    
    errors = []
    tmpdir = mkdtemp()
    files_to_check = []
    try:
        for (file_, content) in files:
            # write staged version of file to temporary directory
            dirname, filename = os.path.split(os.path.abspath(file_))
            prefix = os.path.commonprefix([dirname, tmpdir])
            dirname = os.path.relpath(dirname, start=prefix)
            dirname = os.path.join(tmpdir, dirname)
            if not os.path.isdir(dirname):
                os.makedirs(dirname)
            filename = os.path.join(dirname, filename)
            with open(filename, "wb") as fh:
                fh.write(content)
            files_to_check.append((file_, filename))

        for (file_, filename) in files_to_check:
            errors += list(map(lambda x: "{0}: {1}".format(file_, x),
                               check_file(filename, **options) or []))
    finally:
        shutil.rmtree(tmpdir, ignore_errors=True)

    return errors
1273787
function (r) {
            // If DONE (cancelled), then don't do anything
            if (me.readyState === FileWriter.DONE) {
                return;
            }

            // position always increases by bytes written because file would be extended
            me.position += r;
            // The length of the file is now where we are done writing.

            me.length = me.position;

            // DONE state
            me.readyState = FileWriter.DONE;

            // If onwrite callback
            if (typeof me.onwrite === 'function') {
                me.onwrite(new ProgressEvent('write', { 'target':me }));
            }

            // If onwriteend callback
            if (typeof me.onwriteend === 'function') {
                me.onwriteend(new ProgressEvent('writeend', { 'target':me }));
            }
        }
705502
public function commit()
    {
        foreach ($this->deferredItem as $item) {
            $this->save($item);
        }
        
        $this->deferredItem = [];
    }
1265073
def _commit(self, ref):
        ''
        path_times = self._weakref_path_map[ref]
        path_times.append(nanotime())
        del self._weakref_path_map[ref]
        path = tuple(path_times[1::2])
        times = path_times[::2]
        if path not in self.path_stats:
            # tuple to save a tiny bit of memory
            self.path_stats[path] = tuple([
                Duration(interval=False) for i in range(len(path))])
        path_stats = self.path_stats[path]
        for i in range(1, len(times)):
            path_stats[i - 1]._stats.add(times[i] - times[i - 1])
1081129
def commit(self):
        ""
        if self._meta.path:
            with open(self._meta.path, 'wb') as fd:
                raw = deepcopy(self.raw)
                # LAZY INDEX PROCESSING
                # Save indexes only if not lazy
                lazy_indexes = self.lazy_indexes  # Keep this list safe
                if not self._meta.lazy_indexes:
                    # Remove indexes if needed
                    for idx_name in lazy_indexes:
                        del raw['indexes'][idx_name]
                    for index_name, values in raw['indexes'].items():
                        for value, keys in values.items():
                            raw['indexes'][index_name][value] = list(keys)
                # don't store indexes if not needed
                if not raw['indexes'] or self._meta.lazy_indexes:
                    del raw['indexes']
                try:
                    fd.write(six.u(self.serialize(raw)))
                except TypeError:
                    fd.write(six.b(self.serialize(raw)))
823292
@Managed(description = "Commit locally spooled events for flushing")
    @Override
    public synchronized void forceCommit() throws IOException
    {
        log.debug("Performing commit on delegate EventWriter [{}]", delegate.getClass());
        delegate.commit();

        uncommittedWriteCount = 0;
        lastCommitNanos = getNow();
    }
431917
function writeFiles (files, callback) {
  async.map(files, writeFile.bind(this), function (err) {
    if (err) callback(err);
    callback(null);
  });
}
102561
def _do_write(self):
        
        with self.lock:
            self._commit_counter += 1
            if self._commit_counter >= self._commit_every:
                self._db.commit()
                self._commit_counter = 0
27147
function () {
            var result = new $.Deferred();
            var path = this.path;
            var createIfMissing = this.createIfMissing;
            var recreateIfInvalid = this.recreateIfInvalid;
            var self = this;

            if (path) {
                var prefFile = FileSystem.getFileForPath(path);
                prefFile.read({}, function (err, text) {
                    if (err) {
                        if (createIfMissing) {
                            // Unreadable file is also unwritable -- delete so get recreated
                            if (recreateIfInvalid && (err === FileSystemError.NOT_READABLE || err === FileSystemError.UNSUPPORTED_ENCODING)) {
                                appshell.fs.moveToTrash(path, function (err) {
                                    if (err) {
                                        console.log("Cannot move unreadable preferences file " + path + " to trash!!");
                                    } else {
                                        console.log("Brackets has recreated the unreadable preferences file " + path + ". You may refer to the deleted file in trash in case you need it!!");
                                    }
                                }.bind(this));
                            }
                            result.resolve({});
                        } else {
                            result.reject(new Error("Unable to load preferences at " + path + " " + err));
                        }
                        return;
                    }

                    self._lineEndings = FileUtils.sniffLineEndings(text);

                    // If the file is empty, turn it into an empty object
                    if (/^\s*$/.test(text)) {
                        result.resolve({});
                    } else {
                        try {
                            result.resolve(JSON.parse(text));
                        } catch (e) {
                            if (recreateIfInvalid) {
                                // JSON parsing error -- recreate the preferences file
                                appshell.fs.moveToTrash(path, function (err) {
                                    if (err) {
                                        console.log("Cannot move unparseable preferences file " + path + " to trash!!");
                                    } else {
                                        console.log("Brackets has recreated the Invalid JSON preferences file " + path + ". You may refer to the deleted file in trash in case you need it!!");
                                    }
                                }.bind(this));
                                result.resolve({});
                            } else {
                                result.reject(new ParsingError("Invalid JSON settings at " + path + "(" + e.toString() + ")"));
                            }
                        }
                    }
                });
            } else {
                result.resolve({});
            }

            return result.promise();
        }
276061
def commit(self):
        """"""
        for _, save_dir in self._save_dirs.items():
            save_dir.cleanup()
        self._moves = []
        self._save_dirs = {}
33089
protected synchronized void commit(final boolean optimize) throws IOException
   {
      if (indexReader != null)
      {
         log.debug("committing IndexReader.");
         indexReader.flush();
      }
      if (indexWriter != null)
      {
         log.debug("committing IndexWriter.");
         indexWriter.commit();
      }
      // optimize if requested
      if (optimize)
      {
         IndexWriter writer = getIndexWriter();
         writer.forceMerge(1, true);
         writer.close();
         indexWriter = null;
      }
   }
59466
@Override
  public void commit()
      throws IOException {
    this.closer.close();

    setStagingFileGroup();

    if (!this.fs.exists(this.stagingFile)) {
      throw new IOException(String.format("File %s does not exist", this.stagingFile));
    }

    FileStatus stagingFileStatus = this.fs.getFileStatus(this.stagingFile);

    // Double check permission of staging file
    if (!stagingFileStatus.getPermission().equals(this.filePermission)) {
      this.fs.setPermission(this.stagingFile, this.filePermission);
    }

    this.bytesWritten = Optional.of(Long.valueOf(stagingFileStatus.getLen()));

    LOG.info(String.format("Moving data from %s to %s", this.stagingFile, this.outputFile));
    // For the same reason as deleting the staging file if it already exists, overwrite
    // the output file if it already exists to prevent task retry from being blocked.
    HadoopUtils.renamePath(this.fileContext, this.stagingFile, this.outputFile, true);

    // The staging file is moved to the output path in commit, so rename to add record count after that
    if (this.shouldIncludeRecordCountInFileName) {
      String filePathWithRecordCount = addRecordCountToFileName();
      this.properties.appendToSetProp(this.allOutputFilesPropName, filePathWithRecordCount);
    } else {
      this.properties.appendToSetProp(this.allOutputFilesPropName, getOutputFilePath());
    }

    FsWriterMetrics metrics = new FsWriterMetrics(
        this.id,
        new PartitionIdentifier(this.partitionKey, this.branchId),
        ImmutableSet.of(new FsWriterMetrics.FileInfo(this.outputFile.getName(), recordsWritten()))
    );
    this.properties.setProp(FS_WRITER_METRICS_KEY, metrics.toJson());
 }
925576
function flush(callback) {
    fs.writeFile(_this._filename, JSON.stringify(_this._cache), callback);
  }
442956
def commit(*args, **kwargs):
    
    delayed_queue = get_queue()
    try:
        while delayed_queue:
            queue, args, kwargs = delayed_queue.pop(0)
            queue.original_enqueue_call(*args, **kwargs)
    finally:
        clear()