#3370 kojid: don't fail on missing ccache file
Merged 2 years ago by tkopecek. Opened 2 years ago by tkopecek.
tkopecek/koji issue3369  into  master

file modified
+1 -1
@@ -6624,7 +6624,7 @@ 

              krb_principal = options.host_principal_format % socket.getfqdn()

          try:

              # Check ccache is not empty or authentication will fail

-             if os.stat(options.ccache).st_size == 0:

+             if os.path.exists(options.ccache) and os.stat(options.ccache).st_size == 0:

                  os.remove(options.ccache)

This is a "look before you leap" pattern with os.path.exists(). It's better to call your file operations directly, and ignore the exception if the file does not exist.

Python 3.6+ (ie, CentOS 8) has a FileNotFoundError exception that is handy for this:

try:
    if os.path.getsize(options.ccache) == 0:
        os.remove(options.ccache)
except (FileNotFoundError):
    pass

  

              session.gssapi_login(principal=krb_principal,

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

2 years ago

Metadata Update from @jobrauer:
- Pull-request tagged with: testing-done

2 years ago

Commit d6da86e fixes this pull-request

Pull-Request has been merged by tkopecek

2 years ago

This is a "look before you leap" pattern with os.path.exists(). It's better to call your file operations directly, and ignore the exception if the file does not exist.

Python 3.6+ (ie, CentOS 8) has a FileNotFoundError exception that is handy for this:

try:
    if os.path.getsize(options.ccache) == 0:
        os.remove(options.ccache)
except (FileNotFoundError):
    pass

Maybe better. Anyway, it will mask potential "unlink" problem which raises the same exception. It shouldn't happen, but...

Metadata