| |
@@ -259,7 +259,9 @@
|
| |
# If not change, return
|
| |
if not files and not added:
|
| |
shutil.rmtree(newpath)
|
| |
- os.unlink(lockfile)
|
| |
+ if os.path.exists(lockfile):
|
| |
+ # Remove the lock file
|
| |
+ os.unlink(lockfile)
|
| |
return
|
| |
|
| |
# See if there is a parent to this commit
|
| |
@@ -296,8 +298,9 @@
|
| |
# Remove the clone
|
| |
shutil.rmtree(newpath)
|
| |
|
| |
- # Remove the lock file
|
| |
- os.unlink(lockfile)
|
| |
+ if os.path.exists(lockfile):
|
| |
+ # Remove the lock file
|
| |
+ os.unlink(lockfile)
|
| |
|
| |
|
| |
def clean_git(obj, repo, repofolder):
|
| |
@@ -312,58 +315,66 @@
|
| |
|
| |
# Get the fork
|
| |
repopath = os.path.join(repofolder, repo.path)
|
| |
+ lockfile = '%s.lock' % repopath
|
| |
|
| |
- # Clone the repo into a temp folder
|
| |
- newpath = tempfile.mkdtemp(prefix='pagure-')
|
| |
- new_repo = pygit2.clone_repository(repopath, newpath)
|
| |
+ lock = filelock.FileLock(lockfile)
|
| |
+ with lock:
|
| |
|
| |
- file_path = os.path.join(newpath, obj.uid)
|
| |
+ # Clone the repo into a temp folder
|
| |
+ newpath = tempfile.mkdtemp(prefix='pagure-')
|
| |
+ new_repo = pygit2.clone_repository(repopath, newpath)
|
| |
|
| |
- # Get the current index
|
| |
- index = new_repo.index
|
| |
+ file_path = os.path.join(newpath, obj.uid)
|
| |
|
| |
- # Are we adding files
|
| |
- if not os.path.exists(file_path):
|
| |
- shutil.rmtree(newpath)
|
| |
- return
|
| |
+ # Get the current index
|
| |
+ index = new_repo.index
|
| |
|
| |
- # Remove the file
|
| |
- os.unlink(file_path)
|
| |
+ # Are we adding files
|
| |
+ if not os.path.exists(file_path):
|
| |
+ shutil.rmtree(newpath)
|
| |
+ return
|
| |
+
|
| |
+ # Remove the file
|
| |
+ os.unlink(file_path)
|
| |
|
| |
- # Add the changes to the index
|
| |
- index.remove(obj.uid)
|
| |
+ # Add the changes to the index
|
| |
+ index.remove(obj.uid)
|
| |
|
| |
- # See if there is a parent to this commit
|
| |
- parent = None
|
| |
- if not new_repo.is_empty:
|
| |
- parent = new_repo.head.get_object().oid
|
| |
+ # See if there is a parent to this commit
|
| |
+ parent = None
|
| |
+ if not new_repo.is_empty:
|
| |
+ parent = new_repo.head.get_object().oid
|
| |
+
|
| |
+ parents = []
|
| |
+ if parent:
|
| |
+ parents.append(parent)
|
| |
|
| |
- parents = []
|
| |
- if parent:
|
| |
- parents.append(parent)
|
| |
+ # Author/commiter will always be this one
|
| |
+ author = pygit2.Signature(name='pagure', email='pagure')
|
| |
|
| |
- # Author/commiter will always be this one
|
| |
- author = pygit2.Signature(name='pagure', email='pagure')
|
| |
+ # Actually commit
|
| |
+ new_repo.create_commit(
|
| |
+ 'refs/heads/master',
|
| |
+ author,
|
| |
+ author,
|
| |
+ 'Removed %s %s: %s' % (obj.isa, obj.uid, obj.title),
|
| |
+ new_repo.index.write_tree(),
|
| |
+ parents)
|
| |
+ index.write()
|
| |
|
| |
- # Actually commit
|
| |
- new_repo.create_commit(
|
| |
- 'refs/heads/master',
|
| |
- author,
|
| |
- author,
|
| |
- 'Removed %s %s: %s' % (obj.isa, obj.uid, obj.title),
|
| |
- new_repo.index.write_tree(),
|
| |
- parents)
|
| |
- index.write()
|
| |
+ # Push to origin
|
| |
+ ori_remote = new_repo.remotes[0]
|
| |
+ master_ref = new_repo.lookup_reference('HEAD').resolve()
|
| |
+ refname = '%s:%s' % (master_ref.name, master_ref.name)
|
| |
|
| |
- # Push to origin
|
| |
- ori_remote = new_repo.remotes[0]
|
| |
- master_ref = new_repo.lookup_reference('HEAD').resolve()
|
| |
- refname = '%s:%s' % (master_ref.name, master_ref.name)
|
| |
+ PagureRepo.push(ori_remote, refname)
|
| |
|
| |
- PagureRepo.push(ori_remote, refname)
|
| |
+ # Remove the clone
|
| |
+ shutil.rmtree(newpath)
|
| |
|
| |
- # Remove the clone
|
| |
- shutil.rmtree(newpath)
|
| |
+ if os.path.exists(lockfile):
|
| |
+ # Remove the lock file
|
| |
+ os.unlink(lockfile)
|
| |
|
| |
|
| |
def get_user_from_json(session, jsondata, key='user'):
|
| |
@@ -913,6 +924,10 @@
|
| |
# Remove the clone
|
| |
shutil.rmtree(newpath)
|
| |
|
| |
+ if os.path.exists(lockfile):
|
| |
+ # Remove the lock file
|
| |
+ os.unlink(lockfile)
|
| |
+
|
| |
return os.path.join('files', filename)
|
| |
|
| |
|
| |
@@ -970,7 +985,9 @@
|
| |
# If not change, return
|
| |
if not files and not added:
|
| |
shutil.rmtree(newpath)
|
| |
- os.unlink(lockfile)
|
| |
+ if os.path.exists(lockfile):
|
| |
+ # Remove the lock file
|
| |
+ os.unlink(lockfile)
|
| |
return
|
| |
|
| |
# See if there is a parent to this commit
|
| |
@@ -1011,7 +1028,9 @@
|
| |
try:
|
| |
PagureRepo.push(ori_remote, refname)
|
| |
except pygit2.GitError as err: # pragma: no cover
|
| |
- os.unlink(lockfile)
|
| |
+ if os.path.exists(lockfile):
|
| |
+ # Remove the lock file
|
| |
+ os.unlink(lockfile)
|
| |
shutil.rmtree(newpath)
|
| |
raise pagure.exceptions.PagureException(
|
| |
'Commit could not be done: %s' % err)
|
| |
@@ -1019,8 +1038,9 @@
|
| |
# Remove the clone
|
| |
shutil.rmtree(newpath)
|
| |
|
| |
- # Remove the lock file
|
| |
- os.unlink(lockfile)
|
| |
+ if os.path.exists(lockfile):
|
| |
+ # Remove the lock file
|
| |
+ os.unlink(lockfile)
|
| |
|
| |
return os.path.join('files', filename)
|
| |
|
| |
This to ensure there are no concurrent writing to the repo which could
create dangling commits.
Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr