Skip to content

Commit

Permalink
fix: Pass along released server file descriptor to enable correctly c…
Browse files Browse the repository at this point in the history
…losing server file in when switching from leecher to seeder mode
  • Loading branch information
pojntfx committed Oct 22, 2023
1 parent 0fb279a commit 491533a
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/migration/file_leecher.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (l *FileLeecher) Release() (
chan error,
*sync.WaitGroup,
string,
*os.File,
) {
l.released = true

Expand Down
3 changes: 2 additions & 1 deletion pkg/migration/file_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (s *FileMigrator) Leech(
*services.SeederService,
error,
) {
releasedDev, releasedErrs, releasedWg, releasedDeviceFile := s.leecher.Release()
releasedDev, releasedErrs, releasedWg, releasedDeviceFile, releasedServerFile := s.leecher.Release()

s.released = true
if err := s.leecher.Close(); err != nil {
Expand All @@ -223,6 +223,7 @@ func (s *FileMigrator) Leech(
releasedErrs,
releasedWg,
releasedDeviceFile,
releasedServerFile,

file,
)
Expand Down
2 changes: 2 additions & 0 deletions pkg/migration/file_seeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewFileSeederFromLeecher(
errs chan error,
wg *sync.WaitGroup,
devicePath string,
serverFile *os.File,

deviceFile *os.File,
) *FileSeeder {
Expand All @@ -81,6 +82,7 @@ func NewFileSeederFromLeecher(
errs,
wg,
devicePath,
serverFile,
),

hooks: hooks,
Expand Down
3 changes: 2 additions & 1 deletion pkg/migration/path_leecher.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ func (l *PathLeecher) Release() (
chan error,
*sync.WaitGroup,
string,
*os.File,
) {
l.finalizedCond.L.Lock()
if !l.finalized {
Expand All @@ -336,7 +337,7 @@ func (l *PathLeecher) Release() (

l.released = true

return l.dev, l.errs, l.devWg, l.devicePath
return l.dev, l.errs, l.devWg, l.devicePath, l.serverFile
}

func (l *PathLeecher) Close() error {
Expand Down
3 changes: 2 additions & 1 deletion pkg/migration/path_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (s *PathMigrator) Leech(
*services.SeederService,
error,
) {
releasedDev, releasedErrs, releasedWg, releasedDevicePath := s.leecher.Release()
releasedDev, releasedErrs, releasedWg, releasedDevicePath, releasedServerFile := s.leecher.Release()

s.released = true
if err := s.leecher.Close(); err != nil {
Expand All @@ -249,6 +249,7 @@ func (s *PathMigrator) Leech(
releasedErrs,
releasedWg,
releasedDevicePath,
releasedServerFile,
)

go func() {
Expand Down
2 changes: 2 additions & 0 deletions pkg/migration/path_seeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func NewPathSeederFromLeecher(
errs chan error,
wg *sync.WaitGroup,
devicePath string,
serverFile *os.File,
) *PathSeeder {
if options == nil {
options = &SeederOptions{}
Expand All @@ -113,6 +114,7 @@ func NewPathSeederFromLeecher(
errs: errs,
wg: wg,
devicePath: devicePath,
serverFile: serverFile,
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/migration/slice_leecher.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (l *SliceLeecher) Release() (
chan error,
*sync.WaitGroup,
string,
*os.File,
) {
l.released = true

Expand Down
3 changes: 2 additions & 1 deletion pkg/migration/slice_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (s *SliceMigrator) Leech(
*services.SeederService,
error,
) {
releasedDev, releasedErrs, releasedWg, releasedDeviceSlice := s.leecher.Release()
releasedDev, releasedErrs, releasedWg, releasedDeviceSlice, releasedServerFile := s.leecher.Release()

s.released = true
if err := s.leecher.Close(); err != nil {
Expand All @@ -222,6 +222,7 @@ func (s *SliceMigrator) Leech(
releasedErrs,
releasedWg,
releasedDeviceSlice,
releasedServerFile,

slice,
)
Expand Down
2 changes: 2 additions & 0 deletions pkg/migration/slice_seeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func NewSliceSeederFromLeecher(
errs chan error,
wg *sync.WaitGroup,
devicePath string,
releasedServerFile *os.File,

deviceSlice []byte,
) *SliceSeeder {
Expand All @@ -85,6 +86,7 @@ func NewSliceSeederFromLeecher(
errs,
wg,
devicePath,
releasedServerFile,
),

hooks: hooks,
Expand Down

0 comments on commit 491533a

Please sign in to comment.