mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	write classifier model to temporary file before copying to final location
This commit is contained in:
		@@ -3,6 +3,7 @@ import logging
 | 
			
		||||
import os
 | 
			
		||||
import pickle
 | 
			
		||||
import re
 | 
			
		||||
import shutil
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
 | 
			
		||||
@@ -96,7 +97,10 @@ class DocumentClassifier(object):
 | 
			
		||||
                    raise ClassifierModelCorruptError()
 | 
			
		||||
 | 
			
		||||
    def save(self):
 | 
			
		||||
        with open(settings.MODEL_FILE, "wb") as f:
 | 
			
		||||
        target_file = settings.MODEL_FILE
 | 
			
		||||
        target_file_temp = settings.MODEL_FILE + ".part"
 | 
			
		||||
 | 
			
		||||
        with open(target_file_temp, "wb") as f:
 | 
			
		||||
            pickle.dump(self.FORMAT_VERSION, f)
 | 
			
		||||
            pickle.dump(self.data_hash, f)
 | 
			
		||||
            pickle.dump(self.data_vectorizer, f)
 | 
			
		||||
@@ -107,6 +111,10 @@ class DocumentClassifier(object):
 | 
			
		||||
            pickle.dump(self.correspondent_classifier, f)
 | 
			
		||||
            pickle.dump(self.document_type_classifier, f)
 | 
			
		||||
 | 
			
		||||
        if os.path.isfile(target_file):
 | 
			
		||||
            os.unlink(target_file)
 | 
			
		||||
        shutil.move(target_file_temp, target_file)
 | 
			
		||||
 | 
			
		||||
    def train(self):
 | 
			
		||||
 | 
			
		||||
        data = list()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user