Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
copy Namespace Reference

Functions

 main ()
 

Detailed Description

Emulation of `rm -f out && cp -af` in out. This is necessary on Mac in order
to preserve nanoseconds of mtime. See https://fxbug.dev/56376#c5.

Function Documentation

◆ main()

copy.main ( )

Definition at line 14 of file copy.py.

14def main():
15 if len(sys.argv) != 3:
16 print('usage: copy.py source dest', file=sys.stderr)
17 return 1
18 source = sys.argv[1]
19 dest = sys.argv[2]
20
21 if os.path.isdir(source):
22 print(f'{source} is a directory, tool "copy" does not support directory copies')
23 return 1
24
25 if os.path.exists(dest):
26 if os.path.isdir(dest):
27
28 def _on_error(fn, path, dummy_excinfo):
29 # The operation failed, possibly because the file is set to
30 # read-only. If that's why, make it writable and try the op
31 # again.
32 if not os.access(path, os.W_OK):
33 os.chmod(path, stat.S_IWRITE)
34 fn(path)
35
36 shutil.rmtree(dest, onerror=_on_error)
37 else:
38 if not os.access(dest, os.W_OK):
39 # Attempt to make the file writable before deleting it.
40 os.chmod(dest, stat.S_IWRITE)
41 os.unlink(dest)
42
43 shutil.copy2(source, dest)
44
45
void print(void *str)
Definition bridge.cpp:126
Definition main.py:1