Skip to content

Fix operations with open files - #39

Merged
arthurkiller merged 1 commit into
arthurkiller:masterfrom
mysteriumnetwork:master
Feb 11, 2022
Merged

Fix operations with open files#39
arthurkiller merged 1 commit into
arthurkiller:masterfrom
mysteriumnetwork:master

Conversation

@Guillembonet

@Guillembonet Guillembonet commented Feb 10, 2022

Copy link
Copy Markdown
Contributor

Found a bug when using it on windows: renaming fails because the file is open. I modified the code to only do renaming and removing operations with closed files to avoid these issues on windows. Also, there are some auto-fixes (just 3 space deletes and moving one defer) by the IDE that are nice IMO :)

Closes: #40

Signed-off-by: Guillem Bonet guillem@mysterium.network

Signed-off-by: Guillem Bonet <guillem@mysterium.network>
Comment thread writer.go
Comment thread writer.go
Comment thread writer.go
}

// swap the unsafe pointer
oldfile := atomic.SwapPointer((*unsafe.Pointer)(unsafe.Pointer(&w.file)), unsafe.Pointer(newfile))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

reopen with atomic swap can be safe while writing concurrently.

@Guillembonet Guillembonet Feb 10, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If I don't see the point of swapping the pointers if I have to reopen oldFile anyway. I'm not an expert so maybe you could explain me why it's best. I can modify as you say but I would still need to open oldfile again since I closed it in line 259.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ok, thanks for your contribution. I have to review the code workflow after leaving a long time.

@arthurkiller

Copy link
Copy Markdown
Owner

If you'd like to add windows support to this lib, you can follow the instructions here

@Guillembonet

Copy link
Copy Markdown
Contributor Author

If you'd like to add windows support to this lib, you can follow the instructions here

I think that the approach of moving/deleting open files should not be there anyway as it is allowed in unix but not in general, so I don't see a reason to create specific windows support.

Comment thread writer.go
log.Println("error in compress log file", err)
return
}
closeOnce.Do(func() { oldfile.Close() })

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM

@arthurkiller

arthurkiller commented Feb 10, 2022

Copy link
Copy Markdown
Owner

If you'd like to add windows support to this lib, you can follow the instructions here

I think that the approach of moving/deleting open files should not be there anyway as it is allowed in unix but not in general, so I don't see a reason to create specific windows support.

OK, I have misunderstood what this PR wants to do.

FYI, someone have reported that this lib did not work well with windows platform in #11 and #32

@arthurkiller

Copy link
Copy Markdown
Owner

I will do the test ASAP, then merge this PR
Thx for your contribution

@Guillembonet

Copy link
Copy Markdown
Contributor Author

I will do the test ASAP, then merge this PR Thx for your contribution

Thank you for checking it and reviewing it that fast ;)

@Guillembonet

Guillembonet commented Feb 10, 2022

Copy link
Copy Markdown
Contributor Author

If you'd like to add windows support to this lib, you can follow the instructions here

I think that the approach of moving/deleting open files should not be there anyway as it is allowed in unix but not in general, so I don't see a reason to create specific windows support.

OK, I have misunderstood what this PR wants to do.

FYI, someone have reported that this lib did not work well with windows platform in #11 and #32

You can probably close those now I guess, I think what I did solves that. (at least the one in english the other I don't understand :) )

@arthurkiller
arthurkiller merged commit c19a8e8 into arthurkiller:master Feb 11, 2022
@arthurkiller

Copy link
Copy Markdown
Owner

that's cool ,thx for your contribution @Guillembonet

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.

Volume rolling fails on windows

2 participants