mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
bccda176d4
Summary: This enables O_EXCL to function by allowing the create routine to move its folly::File instance down in to the underlying FileData instance. Previously we would close and then re-open the file; this would discard any of the natural gating for the open call that is performed by the kernel for the underlying filesystem in the overlay. Reviewed By: bolinfest Differential Revision: D3513758 fbshipit-source-id: 85967a3b7affa1b1df46842be8ba21c8fbb843a6
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Copyright (c) 2016, Facebook, Inc.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the BSD-style license found in the
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
from .lib import testcase
|
|
import errno
|
|
import os
|
|
|
|
|
|
class OpenExclusiveTest(testcase.EdenTestCase):
|
|
def test_oexcl(self):
|
|
eden = self.init_git_eden()
|
|
filename = os.path.join(eden.mount_path, 'makeme')
|
|
|
|
fd = os.open(filename, os.O_EXCL | os.O_CREAT | os.O_RDWR)
|
|
self.assertGreater(fd, -1, msg='Opened file exclusively')
|
|
try:
|
|
os.write(fd, b'foo\n')
|
|
finally:
|
|
os.close(fd)
|
|
|
|
with self.assertRaises(OSError) as context:
|
|
fd = os.open(filename, os.O_EXCL | os.O_CREAT | os.O_RDWR)
|
|
if fd != -1:
|
|
os.close(fd)
|
|
self.assertEqual(errno.EEXIST, context.exception.errno,
|
|
msg='O_EXCL for an existing file raises EEXIST')
|
|
|
|
os.unlink(filename)
|
|
|
|
fd = os.open(filename, os.O_EXCL | os.O_CREAT | os.O_RDWR)
|
|
self.assertGreater(fd, -1,
|
|
msg='Subsequent O_EXCL is not blocked after ' +
|
|
'removing the file')
|
|
os.close(fd)
|