Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if uid is not None and self._check_for_duplicate_uids:
self._scan_uids()
try:
(existing_name, _) = self._uid_to_fname[uid]
except KeyError:
pass
else:
if existing_name != name:
raise DuplicateUidError(uid, existing_name, name)
try:
etag = self._get_etag(name)
except KeyError:
etag = None
if replace_etag is not None and etag != replace_etag:
raise InvalidETag(name, etag, replace_etag)
return etag
:param name: Filename to delete
:param message: Commit message
:param author: Optional author
:param etag: Optional mandatory etag of object to remove
:raise NoSuchItem: when the item doesn't exist
:raise InvalidETag: If the specified ETag doesn't match the curren
"""
path = os.path.join(self.path, name)
if etag is not None:
try:
current_etag = self._get_etag(name)
except KeyError:
raise NoSuchItem(name)
if etag != current_etag:
raise InvalidETag(name, etag, current_etag)
try:
os.unlink(path)
except EnvironmentError as e:
if e.errno == errno.ENOENT:
raise NoSuchItem(path)
raise
"""
p = os.path.join(self.repo.path, name)
try:
with open(p, 'rb') as f:
current_blob = Blob.from_string(f.read())
except IOError:
raise NoSuchItem(name)
if message is None:
fi = open_by_extension(current_blob.chunked, name,
self.extra_file_handlers)
message = 'Delete ' + fi.describe(name)
if etag is not None:
with open(p, 'rb') as f:
current_etag = current_blob.id
if etag.encode('ascii') != current_etag:
raise InvalidETag(name, etag, current_etag.decode('ascii'))
try:
with locked_index(self.repo.index_path()) as index:
os.unlink(p)
del index[name.encode(DEFAULT_ENCODING)]
self._commit_tree(index, message.encode(DEFAULT_ENCODING),
author=author)
except FileLocked:
raise LockeError(name)
if uid is not None and self._check_for_duplicate_uids:
self._scan_uids()
try:
(existing_name, _) = self._uid_to_fname[uid]
except KeyError:
pass
else:
if existing_name != name:
raise DuplicateUidError(uid, existing_name, name)
try:
etag = self._get_etag(name)
except KeyError:
etag = None
if replace_etag is not None and etag != replace_etag:
raise InvalidETag(name, etag, replace_etag)
return etag