Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move service generated files to .old (fixes #845) #846

Closed
wants to merge 1 commit into from

Conversation

lnussel
Copy link
Member

@lnussel lnussel commented Sep 30, 2020

fixes #845

@marcus-h
Copy link
Member

marcus-h commented Sep 30, 2020 via email

@adrianschroeter
Copy link
Member

adrianschroeter commented Oct 1, 2020 via email

@lnussel
Copy link
Member Author

lnussel commented Oct 1, 2020

I've updated the code to throw an exception if the directory was not created by the osc run itself

@marcus-h
Copy link
Member

marcus-h commented Oct 1, 2020 via email

@marcus-h
Copy link
Member

marcus-h commented Oct 1, 2020

Sigh... github ignores some mails again...

----- Forwarded message from Marcus Hüwe <suse-tux@gmx.de> -----

Date: Thu, 1 Oct 2020 13:46:06 +0200
From: Marcus Hüwe <suse-tux@gmx.de>
To: reply+AAIEUTBFAPXNRDYWOAO6AFV5QF7SREVBNHHCU3CO44@reply.github.com
Subject: Re: [openSUSE/osc] Move service generated files to .old (fixes #845)
 (#846)

On 2020-10-01 09:15:20 +0000, Ludwig Nussel wrote:
> I've updated the code to throw an exception if the directory was not created by the osc run itself
> 
Thanks! From a usability POV, we should make sure that we always cleanup
the old dir (for instance, if a service fails). What about the following?

diff --git a/osc/core.py b/osc/core.py
index fd2c1a4..f6d1e2c 100644
--- a/osc/core.py
+++ b/osc/core.py
@@ -410,16 +410,27 @@ class Serviceinfo:
return r

 def execute(self, dir, callmode = None, singleservice = None, verbose = None):
  •    old_dir = os.path.join(dir, '.old')
    
  •    if os.path.exists(old_dir) or os.path.islink(old_dir):
    
  •        msg = '"%s" exists, please remove it' % old_dir
    
  •        raise oscerr.OscIOError(None, msg)
    
  •    try:
    
  •        os.mkdir(old_dir)
    
  •        return self._execute(dir, old_dir, callmode, singleservice,
    
  •                             verbose)
    
  •    finally:
    
  •        if os.path.isdir(old_dir):
    
  •            shutil.rmtree(old_dir)
    
  • def _execute(self, dir, old_dir, callmode=None, singleservice=None,
  •             verbose=None):
       import tempfile
    
       # cleanup existing generated files
       for filename in os.listdir(dir):
           if filename.startswith('_service:') or filename.startswith('_service_'):
    
  •            ent = os.path.join(dir, filename)
    
  •            if os.path.isdir(ent):
    
  •                shutil.rmtree(ent)
    
  •            else:
    
  •                os.unlink(ent)
    
  •            os.rename(os.path.join(dir, filename),
    
  •                      os.path.join(old_dir, filename))
    
       allservices = self.services or []
       service_names = [s['name'] for s in allservices]
    

----- End forwarded message -----

@lnussel
Copy link
Member Author

lnussel commented Oct 1, 2020

feel free to throw away my code and put your own :)

marcus-h added a commit to marcus-h/osc that referenced this pull request Oct 1, 2020
Some services expect "old" service files (that is, files from a
previous service run) to be present in an ".old" dir. Hence, osc
should support that.
Instead of removing all files from a previous service run, move them
to the ".old" dir, run the services, and, finally, remove the ".old"
dir.
Unfortunately, the location of the ".old" dir is hardcoded in the
specific services. That is, we have to be careful if an ".old" dir
exists (in this case, we error out).

Based on [1].

[1] openSUSE#846
@marcus-h
Copy link
Member

marcus-h commented Oct 1, 2020 via email

@marcus-h
Copy link
Member

marcus-h commented Oct 1, 2020 via email

@lnussel lnussel closed this Oct 1, 2020
Firstyear pushed a commit to Firstyear/osc that referenced this pull request May 14, 2021
Some services expect "old" service files (that is, files from a
previous service run) to be present in an ".old" dir. Hence, osc
should support that.
Instead of removing all files from a previous service run, move them
to the ".old" dir, run the services, and, finally, remove the ".old"
dir.
Unfortunately, the location of the ".old" dir is hardcoded in the
specific services. That is, we have to be careful if an ".old" dir
exists (in this case, we error out).

Based on [1].

[1] openSUSE#846
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

move service generated files to .old instead of deleting them
3 participants