Skip to content

Conversation

SHAQ522
Copy link
Contributor

@SHAQ522 SHAQ522 commented Dec 16, 2020

For multi user siuation, it may get fail

Permission denied: '/tmp/cz.commit.backup'

The reason is another user has already created a temp file with the same name.
So if one user create temp_file should attatch with $USER info to resolve permission issue

Description

attach user info to temp-file name when $USER is possible

Checklist

  • Add test cases to all the changes you introduce
  • Run ./script/format and ./script/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Expected behavior

create /tmp/cz.commit.backup.tom

Steps to Test This Pull Request

Additional context

For multi user siuation, it may get fail `Permission denied: '/tmp/cz.commit/backup` due to another user create a temp file.
So if one user create temp_file should attatch with USER info to resolve permission issue
@woile
Copy link
Member

woile commented Dec 16, 2020

Nice, thanks! You'll have to run ./scripts/format and the tests will pass

self.temp_file: str = os.path.join(tempfile.gettempdir(), "cz.commit.backup")
name = "cz.commit.backup"
if "USER" in os.environ:
name = name + "." + os.environ['USER']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer something like this:

user = os.environ.get('USER', "")
name = f"cz.commit{user}.backup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the apply. we have 100+ users project using this package which have this issue, but I am new commiter for this python package. I will rebuild this issue only after work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No rush, take your time

name = name + "." + os.environ['USER']
self.temp_file: str = os.path.join(tempfile.gettempdir(), name)

def read_backup_message(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the file be read here?

@SHAQ522 SHAQ522 closed this Dec 16, 2020
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.

2 participants