Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Modified functions using popen #15 #32 #48

Merged
merged 3 commits into from
Aug 15, 2021

Conversation

devkapilbansal
Copy link
Member

Fixes #15
Fixes #32

@devkapilbansal devkapilbansal added this to In progress in [GSoC 2021] OpenWRT OpenWISP Monitoring Package via automation Aug 9, 2021
@devkapilbansal devkapilbansal moved this from In progress to Needs Review in [GSoC 2021] OpenWRT OpenWISP Monitoring Package Aug 9, 2021
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

I did a search in the files of the project and I see two occurrences of io.popen() that are not being changed, can you please double check?

See also my comment below.

output_file:write(command_file:read("*a"))
command_file:close()
output_file:seek('set',0)
return output_file
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't the file be removed once the output is read? And are you sure using tmp files is really necessary?

Wouldn't it be enough to just do:

output = commmand_file:read("*a")
command_file:close()
return output

We weren't doing this before explicitly for every call.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

I did a search in the files of the project and I see two occurrences of io.popen() that are not being changed, can you please double check?

See also my comment below.

@devkapilbansal devkapilbansal changed the title [fix] Modified functions using popen to use temporary files #15 #32 [fix] Modified functions using popen #15 #32 Aug 10, 2021
@devkapilbansal
Copy link
Member Author

I did a search in the files of the project and I see two occurrences of io.popen() that are not being changed, can you please double check?

See also my comment below.

I did it intentionally. The reason being:

  • The utils.popen was getting cached in some cases which results in breaking the tests. The solution can be to mock define utils.popen too in each file which I don't think is a cleaner solution.
  • We need to modify popen only when we are performing operations before closing the file. The only scenario in our case was looping over the output using :lines() function.

@devkapilbansal
Copy link
Member Author

Hi @nemesisdesign , I updated the code to use split instead as we agreed in the chat.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

there's a lot of repetition in this PR, why not create a utility function which does the read, close and returning of the output?

This also ensures that whoever will put their hands on this code will keep reusing our function and avoid messing it up again by forgetting to close a pipe.

@nemesifier nemesifier moved this from Needs Review to In progress in [GSoC 2021] OpenWRT OpenWISP Monitoring Package Aug 12, 2021
@devkapilbansal devkapilbansal force-pushed the issues/15_32-fix-interrupted-system-call branch 2 times, most recently from ba0c7a6 to be0a5bf Compare August 12, 2021 16:28
@devkapilbansal
Copy link
Member Author

there's a lot of repetition in this PR, why not create a utility function which does the read, close and returning of the output?

This also ensures that whoever will put their hands on this code will keep reusing our function and avoid messing it up again by forgetting to close a pipe.

I too tried doing something similar. But if I do it in utils function and import it in other sub-modules, then it may not be possible for now to keep them separated from one another. The cache property of require is breaking the functionalities in tests 😕

@nemesifier
Copy link
Member

there's a lot of repetition in this PR, why not create a utility function which does the read, close and returning of the output?
This also ensures that whoever will put their hands on this code will keep reusing our function and avoid messing it up again by forgetting to close a pipe.

I too tried doing something similar. But if I do it in utils function and import it in other sub-modules, then it may not be possible for now to keep them separated from one another. The cache property of require is breaking the functionalities in tests

I hope we can find a way to do it, it would be better, I created an issue here: #61.

command_file:close()
return output
end

Copy link
Member

Choose a reason for hiding this comment

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

duplicating the same function in each file is actually worse Kapil. If duplicating two lines of code is not good, how can duplicating 6 lines of code be better? Please rollback how it was before.

[GSoC 2021] OpenWRT OpenWISP Monitoring Package automation moved this from In progress to Needs Review Aug 13, 2021
@devkapilbansal devkapilbansal force-pushed the issues/15_32-fix-interrupted-system-call branch from be0a5bf to 048db7b Compare August 13, 2021 11:01
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

Thanks

[GSoC 2021] OpenWRT OpenWISP Monitoring Package automation moved this from Needs Review to Reviewer approved Aug 15, 2021
@nemesifier nemesifier merged commit 3740362 into gsoc21 Aug 15, 2021
[GSoC 2021] OpenWRT OpenWISP Monitoring Package automation moved this from Reviewer approved to Done Aug 15, 2021
@devkapilbansal devkapilbansal deleted the issues/15_32-fix-interrupted-system-call branch August 15, 2021 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants