Skip to content

Commit

Permalink
Rename testdata folder for manually managed problems on change code (#…
Browse files Browse the repository at this point in the history
…200)

If we change the problem code of a problem, its testdata folder will be renamed
to the new code. But that logic was not applied for manually managed problems.

This commit fixed it.
  • Loading branch information
leduythuccs committed Oct 6, 2021
1 parent 9981d3f commit 8ac3950
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion judge/models/problem.py
@@ -1,3 +1,4 @@
import errno
from operator import attrgetter

import celery
Expand All @@ -16,6 +17,7 @@
from django.utils.translation import gettext_lazy as _

from judge.fulltext import SearchQuerySet
from judge.models.problem_data import problem_data_storage
from judge.models.profile import Organization, Profile
from judge.models.runtime import Language
from judge.user_translations import gettext as user_gettext
Expand Down Expand Up @@ -479,16 +481,26 @@ def save(self, *args, **kwargs):
try:
problem_data = self.data_files
except AttributeError:
pass
try:
problem_data_storage.rename(self.__original_code, self.code)
except OSError as e:
if e.errno != errno.ENOENT:
raise
else:
problem_data._update_code(self.__original_code, self.code)
# Now the instance is saved, we need to update the original code to
# new code so that if the user uses .save() multiple time, it will not run
# update_code() multiple time
self.__original_code = self.code

# self.__original_points will be None if:
# - create new instance (should ignore)
# - The `points` field got deferred (not sure about this?)
# in both cases, we don't rescore submissions.
if self.__original_points is not None and self.points != self.__original_points:
self._rescore()
# same reason as update __original_code
self.__original_points = self.points

save.alters_data = True

Expand Down

0 comments on commit 8ac3950

Please sign in to comment.