def link_fd_to_path(fd, target_path, dirs_created=0, retries=2, fsync=True):
 dirpath = os.path.dirname(target_path)
 for _junk in range(0, retries):
  try:
   linkat(linkat.AT_FDCWD, ('/proc/self/fd/%d' % fd), linkat.AT_FDCWD, target_path, linkat.AT_SYMLINK_FOLLOW)
   break
  except IOError as err:
   if (err.errno == errno.ENOENT):
    dirs_created = makedirs_count(dirpath)
   elif (err.errno == errno.EEXIST):
    try:
     os.unlink(target_path)
    except OSError as e:
     if (e.errno != errno.ENOENT):
      raise
   else:
    raise
 if fsync:
  for i in range(0, (dirs_created + 1)):
   fsync_dir(dirpath)
   dirpath = os.path.dirname(dirpath)

def link_fd_to_path ( fd , target_path , dirs_created = 0 , retries = 2 , fsync = True ) : dirpath = os . path . dirname ( target_path ) for _junk in range ( 0 , retries ) : try : linkat ( linkat . AT_FDCWD , ( '/proc/self/fd/%d' % fd ) , linkat . AT_FDCWD , target_path , linkat . AT_SYMLINK_FOLLOW ) break except IOError as err : if ( err . errno == errno . ENOENT ) : dirs_created = makedirs_count ( dirpath ) elif ( err . errno == errno . EEXIST ) : try : os . unlink ( target_path ) except OSError as e : if ( e . errno != errno . ENOENT ) : raise else : raise if fsync : for i in range ( 0 , ( dirs_created + 1 ) ) : fsync_dir ( dirpath ) dirpath = os . path . dirname ( dirpath )
creates a link to file descriptor at target_path specified .