MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / atomic_write_string_to_file

Function atomic_write_string_to_file

tensorflow/python/lib/io/file_io.py:522–543  ·  view source on GitHub ↗

Writes to `filename` atomically. This means that when `filename` appears in the filesystem, it will contain all of `contents`. With write_string_to_file, it is possible for the file to appear in the filesystem with `contents` only partially written. Accomplished by writing to a temp file a

(filename, contents, overwrite=True)

Source from the content-addressed store, hash-verified

520
521
522def atomic_write_string_to_file(filename, contents, overwrite=True):
523 """Writes to `filename` atomically.
524
525 This means that when `filename` appears in the filesystem, it will contain
526 all of `contents`. With write_string_to_file, it is possible for the file
527 to appear in the filesystem with `contents` only partially written.
528
529 Accomplished by writing to a temp file and then renaming it.
530
531 Args:
532 filename: string, pathname for a file
533 contents: string, contents that need to be written to the file
534 overwrite: boolean, if false it's an error for `filename` to be occupied by
535 an existing file.
536 """
537 temp_pathname = filename + ".tmp" + uuid.uuid4().hex
538 write_string_to_file(temp_pathname, contents)
539 try:
540 rename(temp_pathname, filename, overwrite)
541 except errors.OpError:
542 delete_file(temp_pathname)
543 raise
544
545
546@tf_export(v1=["gfile.DeleteRecursively"])

Callers

nothing calls this directly

Calls 3

write_string_to_fileFunction · 0.85
renameFunction · 0.85
delete_fileFunction · 0.70

Tested by

no test coverage detected