File.chown bad pattern invalid character set unterminated character

Hi everyone, today, when I was doing another test of my package manager, I faced this error:

Failed to set the owner uid:root and gid:root at the path /mnt/ism/usr
#<File::BadPatternError:Invalid character set: unterminated character set>

The call is from this portion of code:

@@changeOwnerDirs.each do |dir|
                setOwnerRecursively("#{Ism.settings.rootPath}#{dir}","root","root")
            end

The value of the array (fail at the first entry):

@@changeOwnerDirs = [ "/usr","/lib","/lib64","/var","/etc","/bin","/sbin","/tmp","/boot","#{ISM::Default::Path::ToolsDirectory}","#{ISM::Default::Path::SourcesDirectory}","/.","/.."]

And the implementation of my function setOwnerRecursively:

def setOwner(path : String, uid : Int | String, gid : Int | String)
            begin
                File.chown( path,
                            (uid.is_a?(String) ? System::Group.find_by(name: uid).id : uid).to_i,
                            (gid.is_a?(String) ? System::Group.find_by(name: gid).id : gid).to_i)
            rescue error
                Ism.notifyOfSetOwnerError(path, uid, gid, error)
                Ism.exitProgram
            end
        end

        def setOwnerRecursively(path : String, uid : Int | String, gid : Int | String)
            begin
                Dir.glob(Dir["#{path}/**/*"]) do |file_path|
                    setOwner(path, uid, gid)
                end
            rescue error
                Ism.notifyOfSetOwnerRecursivelyError(path, uid, gid, error)
                Ism.exitProgram
            end
        end

Any idea ? Because I don’t see where this problem come from to be honest.

Should it be setOwner(file_path, uid, gid)?

Edit: isn’t Dir[...] the same as Dir.glob(...) too? It looks weird that you’re using both and I can’t quite grok why :sweat_smile:

1 Like

Yes during the time you was writing, I saw I did a mistake with path, shoudl be file_path

I will have a look about the thing you say about Dir, I feel I didn’t a bad copy past of my previous code

EDIT: So yes this fix the problem :sweat_smile:
This happen when you try to do to much code and copy paste your previous code xD

Thanks a lot

1 Like