From: <pj...@us...> - 2009-05-26 06:51:06
|
Revision: 6381 http://jython.svn.sourceforge.net/jython/?rev=6381&view=rev Author: pjenvey Date: 2009-05-26 06:50:56 +0000 (Tue, 26 May 2009) Log Message: ----------- add os.fsync/datasync Modified Paths: -------------- trunk/jython/Lib/os.py Modified: trunk/jython/Lib/os.py =================================================================== --- trunk/jython/Lib/os.py 2009-05-26 06:49:37 UTC (rev 6380) +++ trunk/jython/Lib/os.py 2009-05-26 06:50:56 UTC (rev 6381) @@ -30,9 +30,9 @@ 'O_RDWR', 'O_SYNC', 'O_TRUNC', 'O_WRONLY', 'R_OK', 'SEEK_CUR', 'SEEK_END', 'SEEK_SET', 'W_OK', 'X_OK', '_exit', 'access', 'altsep', 'chdir', 'chmod', 'close', 'curdir', 'defpath', - 'environ', 'error', 'fdopen', 'getcwd', 'getcwdu', 'getenv', - 'getpid', 'isatty', 'linesep', 'listdir', 'lseek', 'lstat', - 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', + 'environ', 'error', 'fdopen', 'fsync', 'getcwd', 'getcwdu', + 'getenv', 'getpid', 'isatty', 'linesep', 'listdir', 'lseek', + 'lstat', 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', 'pathsep', 'popen', 'popen2', 'popen3', 'popen4', 'putenv', 'read', 'remove', 'removedirs', 'rename', 'renames', 'rmdir', 'sep', 'stat', 'stat_result', 'strerror', 'system', 'unlink', @@ -1048,10 +1048,41 @@ raise OSError(status[0], strerror(status[0])) return res_pid, status[0] + def fdatasync(fd): + """fdatasync(fildes) + + force write of file with filedescriptor to disk. + does not force update of metadata. + """ + _fsync(fd, False) + __all__.extend(['link', 'symlink', 'readlink', 'getegid', 'geteuid', 'getgid', 'getlogin', 'getpgrp', 'getppid', 'getuid', - 'setpgrp', 'setsid', 'kill', 'wait', 'waitpid']) + 'setpgrp', 'setsid', 'kill', 'wait', 'waitpid', + 'fdatasync']) +def fsync(fd): + """fsync(fildes) + + force write of file with filedescriptor to disk. + """ + _fsync(fd, True) + +def _fsync(fd, metadata): + """Internal fsync impl""" + rawio = FileDescriptors.get(fd) + rawio.checkClosed() + + from java.nio.channels import FileChannel + channel = rawio.getChannel() + if not isinstance(channel, FileChannel): + raise OSError(errno.EINVAL, strerror(errno.EINVAL)) + + try: + channel.force(metadata) + except java.io.IOException, ioe: + raise OSError(ioe) + def getpid(): """getpid() -> pid This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |