문제

Has anyone else encountered a file locking issue with Ramaze on Windows? All my uploaded files are being locked (I'm using the upload helper btw).

I'm using - Ruby 1.93 - Ramaze-2012.04.14 - Rack-1.4.1

Thanks!

도움이 되었습니까?

해결책

Answering my own question. Looks like the culprit's this line in ramaze/helper/upload.rb

@realfile = File.new(path) #--->this opens the uploaded/saved file, thus locking it

I patched my local copy of upload.rb with this --

class UploadedFile
    include Ramaze::Traited

    # Suggested file name
    # @return [String]
    attr_reader :filename

    # MIME-type
    # @return [String]
    attr_reader :type

    # Saved file object
    # @return [File]
    attr_reader :realfile #---> expose the variable so we can close it from the caller

And then in your caller, simply close the file after you save it, like so...

get_uploaded_files.each_pair{|k, v|
    v.save "upload/#{v.filename}"
    v.realfile.close #close the file handle
}

I will be submitting a patch soon...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top