Hi everyone, recently I had a bug when my program is writing .json file.
At the beginning I have a .json file like that one:
{
"port": "KdeSoftwares-Main",
"name": "Plasma-Desktop",
"version": "5.22.4",
"architectures": [
"x86_64"
],
"description": "The Plasma KDE workspace",
"website": "https://kde.org/plasma-desktop/",
"installedFiles": [],
"dependencies": [
{
"name": "Accountsservice",
"version": "0.6.55",
"options": []
},
{
"name": "Gtk+",
"version": "2.24.33",
"options": []
},
{
"name": "Gtk+",
"version": "3.24.30",
"options": []
},
{
"name": "Kde-Frameworks",
"version": "5.85.0",
"options": []
},
{
"name": "Libpwquality",
"version": "1.4.4",
"options": []
},
{
"name": "Libxkbcommon",
"version": "1.3.0",
"options": []
},
{
"name": "Mesa",
"version": "21.2.1",
"options": [
"Wayland-Protocols"
]
},
{
"name": "Qca",
"version": "2.3.3",
"options": []
},
{
"name": "Sassc",
"version": "3.6.2",
"options": []
},
{
"name": "Taglib",
"version": "1.12.0",
"options": []
},
{
"name": "Xcb-Util-Cursor",
"version": "0.1.3",
"options": []
},
{
"name": "Kdecoration",
"version": "5.22.4",
"options": []
},
{
"name": "Libkscreen",
"version": "5.22.4",
"options": []
},
{
"name": "Libksysguard",
"version": "5.22.4",
"options": []
},
{
"name": "Breeze",
"version": "5.22.4",
"options": []
},
{
"name": "Breeze-Gtk",
"version": "5.22.4",
"options": []
},
{
"name": "Layer-Shell-Qt",
"version": "5.22.4",
"options": []
},
{
"name": "Kscreenlocker",
"version": "5.22.4",
"options": []
},
{
"name": "Oxygen",
"version": "5.22.4",
"options": []
},
{
"name": "Kinfocenter",
"version": "5.22.4",
"options": []
},
{
"name": "Kwayland-Server",
"version": "5.22.4",
"options": []
},
{
"name": "Kwin",
"version": "5.22.4",
"options": []
},
{
"name": "Plasma-Workspace",
"version": "5.22.4",
"options": []
},
{
"name": "Kdecoration",
"version": "5.22.4",
"options": []
},
{
"name": "Kde-Gtk-Config",
"version": "5.22.4",
"options": []
},
{
"name": "Khotkeys",
"version": "5.22.4",
"options": []
},
{
"name": "Kmenuedit",
"version": "5.22.4",
"options": []
},
{
"name": "Kscreen",
"version": "5.22.4",
"options": []
},
{
"name": "Kwallet-Pam",
"version": "5.22.4",
"options": []
},
{
"name": "Kwayland-Integration",
"version": "5.22.4",
"options": []
},
{
"name": "Kwrited",
"version": "5.22.4",
"options": []
},
{
"name": "Milou",
"version": "5.22.4",
"options": []
},
{
"name": "Plasma-Workspace-Wallpapers",
"version": "5.22.4",
"options": []
},
{
"name": "Polkit-Kde-Agent-1",
"version": "5.22.4",
"options": []
},
{
"name": "Powerdevil",
"version": "5.22.4",
"options": []
},
{
"name": "Kdeplasma-Addons",
"version": "5.22.4",
"options": []
},
{
"name": "Kgamma5",
"version": "5.22.4",
"options": []
},
{
"name": "Kactivitymanagerd",
"version": "5.22.4",
"options": []
},
{
"name": "Plasma-Integration",
"version": "5.22.4",
"options": []
},
{
"name": "Plasma-Browser-Integration",
"version": "5.22.4",
"options": []
},
{
"name": "Kde-Cli-Tools",
"version": "5.22.4",
"options": []
},
{
"name": "Systemsettings",
"version": "5.22.4",
"options": []
},
{
"name": "Qqc2-Breeze-Style",
"version": "5.22.4",
"options": []
},
{
"name": "Ksystemstats",
"version": "5.22.4",
"options": []
}
],
"kernelDependencies": [],
"options": [
{
"name": "Linux-Pam",
"description": "Enable linux-pam support",
"active": true,
"dependencies": [
{
"name": "Linux-Pam",
"version": "1.5.1",
"options": []
}
],
"kernelDependencies": []
},
{
"name": "Bluedevil",
"description": "Enable bluedevil support",
"active": true,
"dependencies": [
{
"name": "Bluedevil",
"version": "5.22.4",
"options": []
}
],
"kernelDependencies": []
},
{
"name": "NetworkManager",
"description": "Enable networkmanager support",
"active": true,
"dependencies": [
{
"name": "Plasma-Nm",
"version": "5.22.4",
"options": []
},
{
"name": "NetworkManager-Qt",
"version": "5.85.0",
"options": []
}
],
"kernelDependencies": []
},
{
"name": "ModemManager",
"description": "Enable modemmanager support",
"active": true,
"dependencies": [
{
"name": "ModemManager-Qt",
"version": "5.85.0",
"options": []
}
],
"kernelDependencies": []
},
{
"name": "Pulseaudio",
"description": "Enable pulseaudio support",
"active": true,
"dependencies": [
{
"name": "Pulseaudio",
"version": "15.0.0",
"options": []
},
{
"name": "Plasma-Pa",
"version": "5.22.4",
"options": []
}
],
"kernelDependencies": []
},
{
"name": "Phonon-Backend-Gstreamer",
"description": "Enable gstreamer backend support",
"active": true,
"dependencies": [
{
"name": "Phonon-Backend-Gstreamer",
"version": "4.10.0",
"options": []
}
],
"kernelDependencies": []
},
{
"name": "Phonon-Backend-Vlc",
"description": "Enable vlc backend support",
"active": false,
"dependencies": [
{
"name": "Phonon-Backend-Vlc",
"version": "0.11.3",
"options": []
}
],
"kernelDependencies": []
},
{
"name": "Sddm",
"description": "Enable sddm support",
"active": false,
"dependencies": [
{
"name": "Sddm",
"version": "0.19.0",
"options": []
},
{
"name": "Sddm-Kcm",
"version": "5.22.4",
"options": []
}
],
"kernelDependencies": []
}
],
"uniqueOptions": []
}
If I just load this file, the class is loaded properly from the file. But if now I use the function writeInformationFile, and then I load the generated file, the member @dependencies of this class become wrong, I have some dependencies not suppose to be dependencies
Do you think something is wrong in my class implementation ? (I just share the relevant part)
module ISM
class SoftwareInformation
def_clone
include JSON::Serializable
property port : String
property name : String
property version : String
property architectures : Array(String)
property description : String
property website : String
property installedFiles : Array(String)
setter dependencies : Array(ISM::SoftwareDependency)
setter kernelDependencies : Array(String)
property options : Array(ISM::SoftwareOption)
property uniqueOptions : Array(Array(String))
def initialize( @port = String.new,
@name = String.new,
@version = String.new,
@architectures = Array(String).new,
@description = String.new,
@website = String.new,
@installedFiles = Array(String).new,
@dependencies = Array(ISM::SoftwareDependency).new,
@kernelDependencies = Array(String).new,
@options = Array(ISM::SoftwareOption).new,
@uniqueOptions = Array(Array(String)).new)
end
def loadInformationFile(loadInformationFilePath : String)
begin
information = SoftwareInformation.from_json(File.read(loadInformationFilePath))
rescue error : JSON::ParseException
puts "#{ISM::Default::SoftwareInformation::FileLoadProcessSyntaxErrorText1 +
loadInformationFilePath +
ISM::Default::SoftwareInformation::FileLoadProcessSyntaxErrorText2 +
error.line_number.to_s}".colorize(:yellow)
return
end
@port = information.port
@name = information.name
@version = information.version
@architectures = information.architectures
@description = information.description
@website = information.website
@installedFiles = information.installedFiles
@dependencies = information.dependencies
@kernelDependencies = information.kernelDependencies
@options = information.options
@uniqueOptions = information.uniqueOptions
end
def writeInformationFile(writeInformationFilePath : String)
path = writeInformationFilePath.chomp(writeInformationFilePath[writeInformationFilePath.rindex("/")..-1])
if !Dir.exists?(path)
Dir.mkdir_p(path)
end
information = SoftwareInformation.new( @port,
@name,
@version,
@architectures,
@description,
@website,
@installedFiles,
@dependencies,
@kernelDependencies,
@options,
@uniqueOptions)
file = File.open(writeInformationFilePath,"w")
information.to_json(file)
file.close
end