Writes a file if it doesn't already exist with the same content.

  This is useful because cargo uses timestamps to decide whether to compile things.
7453
def _replace_file(path, content):
  """"""
  if os.path.exists(path):
    with open(path, 'r') as f:
      if content == f.read():
        print("Not overwriting {} because it is unchanged".format(path), file=sys.stderr)
        return

  with open(path, 'w') as f:
    f.write(content)
418070
function saveFile(filename, data, overwrite) {
  if (overwrite) {
    return fs.outputFile(filename, data)
      .then(() => filename);
  } else {
    return new Promise((resolve, reject) => {
      fsu.writeFileUnique(
        filename.replace(fileExtRegex, '{_###}$&'),
        data,
        { force: true },
        (err, savedFile) => err === null ? resolve(savedFile) : reject(err)
      );
    });
  }
}
800155
function writeFile(namespace, fileName, fileLocation) {
  if (!gfsPromise) {
    return;
  }
  return gfsPromise.then(function(gfs) {
    var deferred = q.defer();
    var options = {
      filename: fileName
    };
    if (namespace) {
      options.root = namespace;
    }
    var writeStream = gfs.createWriteStream(options);
    writeStream.on('error', function(err) {
      console.log('An error occurred!', err);
      deferred.reject(err);
    });
    writeStream.on('close', function(file) {
      deferred.resolve(file);
    });
    fs.createReadStream(fileLocation).pipe(writeStream);
    return deferred.promise;
  });
}
704148
public boolean createNewFile() throws IOException
  {
    synchronized (LOCK) {
      if (! exists()) {
        clearStatusCache();
        WriteStreamOld s = openWrite();
        s.close();
        return true;
      }
    }

    return false;
  }
704530
def write(content, filename='cache'):
	
	cache_path = get_cache_path(filename)
	with open(cache_path, 'w') as file:
		if content is not None:
			json.dump(content, file, indent=3, sort_keys=True)
1082287
private void writeToFile(MemoryCommitResult mcr) {
        // Rename the current file so it may be used as a backup during the next read
        if (mFile.exists()) {
            if (!mcr.changesMade) {
                // If the file already exists, but no changes were
                // made to the underlying map, it's wasteful to
                // re-write the file.  Return as if we wrote it
                // out.
                mcr.setDiskWriteResult(true);
                return;
            }
            if (!mBackupFile.exists()) {
                if (!mFile.renameTo(mBackupFile)) {
                    System.out.println( "Couldn't rename file " + mFile
                            + " to backup file " + mBackupFile);
                    mcr.setDiskWriteResult(false);
                    return;
                }
            } else {
                mFile.delete();
            }
        }

        // Attempt to write the file, delete the backup and return true as atomically as
        // possible.  If any exception occurs, delete the new file; next time we will restore
        // from the backup.
        try {
            FileOutputStream str = createFileOutputStream(mFile);
            if (str == null) {
                mcr.setDiskWriteResult(false);
                return;
            }
            XmlUtils.writeMapXml(mcr.mapToWriteToDisk, str);
            FileUtils.sync(str);
            str.close();
            setFilePermissionsFromMode(mFile.getPath(), mMode, 0);
            if (mFile.canRead()) {
                synchronized (this) {
                    mStatTimestamp = mFile.lastModified();
                    mStatSize = mFile.length();
                }
            }
            // Writing was successful, delete the backup file if there is one.
            mBackupFile.delete();
            mcr.setDiskWriteResult(true);
            return;
        } catch (IOException e) {
            System.out.println("writeToFile: Got exception:" + e);
        }
        // Clean up an unsuccessfully written file
        if (mFile.exists()) {
            if (!mFile.delete()) {
                System.out.println("Couldn't clean up partially-written file " + mFile);
            }
        }
        mcr.setDiskWriteResult(false);
    }
655726
def add_file(filename, content)
      return if @sandbox

      filepath = File.join(Configuration.instance.get(:path), filename)
      if File.exist?(filepath)
        puts "File #{filepath} already exists."
        return
      end

      FileUtils.mkdir_p File.dirname(filepath)
      File.open filepath, 'w' do |file|
        file.write content
      end
    end
433939
def write_file(path, contents):
	""""""
	os.makedirs(os.path.dirname(path), exist_ok=True)
	with open(path, "w") as file:
		file.write(contents)
1057700
def file_append(filepath, newcontent, backup=false)
      content = StringIO.new
      
      if self.file_exists?(filepath)
        self.cp filepath, "#{filepath}-previous" if backup
        content = self.file_download filepath
      end
      
      if newcontent.is_a?(StringIO)
        newcontent.rewind
        content.puts newcontent.read
      else
        content.puts newcontent
      end
      
      self.file_upload content, filepath
    end
947005
def make_file(path, contents='', overwrite=False):
    
    if overwrite or not os.path.exists(path):
        with open(path, 'w') as fh:
            fh.write(contents)
        return True

    return False
130532
function writeFile(input, output, type) {
    var json    = readFile(input),
        content = getContent(json, type);

    fs.writeFile(output, content, function (err) {
        if (err) {
            throw err;
        }

        console.log('The file "' + output + '" was written successfully!');
    });
}
305279
function writeFile(filename, content) {
  fs.writeFileSync(filename, JSON.stringify(content, null, 2));
}
208725
def write_file_content(path, data)
      ::File.open(::File.join(path), "wb") do |f|
        data.each do |item|
          f.write("[#{item[:header]}]\n")
          f.write("#{item[:content]}\n")
        end
      end
    end
54277
function write (item) {

  var filename = item.file;
  var message = item.message;
  var header = item.header;
  var file = path.join(p_, filename);

  fs.exists(file, function (exists) {
    if (exists) {
      fs.appendFile(file, message, function () {
        task();
      });

    } else {
      if (header) {
        message = header + EOL + message;
      }

      var dir = path.dirname(file);
      fs.exists(dir, function (exists) {
        if (exists) {
          fs.appendFile(file, message, function () {
            task();
          });

        } else {
          fs.mkdirs(dir, function (err) {
            if (err) {
              console.error(err);
              task();
            } else {
              fs.appendFile(file, message, function () {
                task();
              });
            }
          });
        }
      });
    }
  });
}
851693
function createFile(file) {
    fs.ensureFileSync(file.name);
    fs.writeFileSync(file.name, file.source);
    return;
}
620813
def write(self, nml_path, force=False, sort=False):
        
        nml_is_file = hasattr(nml_path, 'read')
        if not force and not nml_is_file and os.path.isfile(nml_path):
            raise IOError('File {0} already exists.'.format(nml_path))

        nml_file = nml_path if nml_is_file else open(nml_path, 'w')
        try:
            self._writestream(nml_file, sort)
        finally:
            if not nml_is_file:
                nml_file.close()
801676
def writefile(openedfile, newcontents):
    """"""
    openedfile.seek(0)
    openedfile.truncate()
    openedfile.write(newcontents)