package org.mitallast.queue.raft.log;

import com.google.inject.Inject;
import org.mitallast.queue.common.component.AbstractComponent;
import org.mitallast.queue.common.settings.Settings;

import java.io.File;
import java.io.IOException;

public class SegmentIndexService extends AbstractComponent {

    private final SegmentFileService fileService;

    @Inject
    public SegmentIndexService(Settings settings, SegmentFileService fileService) {
        super(settings);
        this.fileService = fileService;
    }

    public SegmentIndex createIndex(SegmentDescriptor descriptor) throws IOException {
        File file = fileService.createIndexFile(descriptor);
        if (file.exists()) {
            if (!file.createNewFile()) {
                throw new IOException("Error create io file");
            }
        }
        return new SegmentIndex(file, (int) descriptor.maxEntries());
    }

    public void deleteIndex(SegmentDescriptor descriptor) throws IOException {
        File file = fileService.createIndexFile(descriptor);
        if (file.exists()) {
            assert file.delete();
        }
    }
}

@@ -665,32 +665,33 @@
 r);%0A        if (
+!
 file.exists()) %7B

fix raft segment index service