Back to index

python3.2  3.2.2
Functions | Variables
_emx_link Namespace Reference

Functions

def link

Variables

list __all__ = ['link']

Function Documentation

def _emx_link.link (   source,
  target 
)
link(source, target) -> None

Attempt to hard link the source file to the target file name.
On OS/2, this creates a complete copy of the source file.

Definition at line 41 of file _emx_link.py.

00041 
00042 def link(source, target):
00043     """link(source, target) -> None
00044 
00045     Attempt to hard link the source file to the target file name.
00046     On OS/2, this creates a complete copy of the source file.
00047     """
00048 
00049     s = os.open(source, os.O_RDONLY | os.O_BINARY)
00050     if os.isatty(s):
00051         raise OSError(errno.EXDEV, 'Cross-device link')
00052     data = os.read(s, 1024)
00053 
00054     try:
00055         t = os.open(target, os.O_WRONLY | os.O_BINARY | os.O_CREAT | os.O_EXCL)
00056     except OSError:
00057         os.close(s)
00058         raise
00059 
00060     try:
00061         while data:
00062             os.write(t, data)
00063             data = os.read(s, 1024)
00064     except OSError:
00065         os.close(s)
00066         os.close(t)
00067         os.unlink(target)
00068         raise
00069 
00070     os.close(s)
00071     os.close(t)


Variable Documentation

list _emx_link.__all__ = ['link']

Definition at line 39 of file _emx_link.py.