docs: def copy_content(origin, dstPath, blockSize, mode):
      ''' copy the content of `origin` to `dstPath` in a safe manner.
  
          this function will first copy the content to a temporary file
          and then move it atomically to the requested destination.
  
          if some error occurred during content copy or file movement
          the temporary file will be deleted.
      '''
      tmpFD, tmpPath = tempfile.mkstemp(prefix=os.path.basename(dstPath) + "_", suffix='.tmp', dir=os.path.dirname(dstPath))
      try:
          try:
              # change mode of the temp file
              oldmask = os.umask(0)
              try:
                  os.chmod(tmpPath, mode)
              finally:
                  os.umask(oldmask)
              # copy content to temporary file
              while True:
                  chunk = origin.read(blockSize)
                  if not chunk:
                      break
                  os.write(tmpFD, chunk)
          finally:
              os.close(tmpFD)
  
          # move temporary file to actual requested destination
          try:
              os.rename(tmpPath, dstPath)
          except OSError as e:
              # on Windows if dstPath already exists at renaming time, an OSError is raised.
              if platform.system() is 'Windows' and e.errno is errno.EEXIST:
                  pass
              else:
                  raise
      except:
          os.remove(tmpPath)
          raise