| 159 | === WPS object creation === |
| 160 | |
| 161 | RPM provides a number of macros to create WPS objects for your package from %post and %postun scriplets. These macros start with {{{%wps_object_}}}. All WPS objects created using these macros are associated with the package and recorded in a special database. Each object also has a reference count (which is increased when the object is created and decreased when it is deleted). The physical object deletion only happens when the reference count drops to zero. This is useful for objects (e.g. application folders) shared between several packages since it allows to keep them alive as long as there is one or more packages referencing them installed and automatically remove these shared objects once all of the referencing packages are removed. |
| 162 | |
| 163 | Here is an example: |
| 164 | {{{ |
| 165 | %post |
| 166 | if [ "$1" -ge 1 ]; then # (upon update) |
| 167 | %wps_object_delete_all |
| 168 | fi |
| 169 | %wps_object_create_begin |
| 170 | MYAPP_EXE:WPProgram|My App|<WP_DESKTOP>|EXENAME=((%{_bindir}/myapp.exe)) |
| 171 | %wps_object_create_end |
| 172 | |
| 173 | %postun |
| 174 | if [ "$1" -e 0 ]; then # (upon removal) |
| 175 | %wps_object_delete_all |
| 176 | fi |
| 177 | }}} |
| 178 | |
| 179 | For a sub-package named "extras", the scriptlets will look as follows: |
| 180 | {{{ |
| 181 | %post extras |
| 182 | if [ "$1" -ge 1 ]; then # (upon update) |
| 183 | %wps_object_delete_all -n %{name}-extras |
| 184 | fi |
| 185 | %wps_object_create_begin -n %{name}-extras |
| 186 | MYAPP_EXTRAS_FOLDER:WPFolder|My App Extras|<WP_DESKTOP> |
| 187 | MYAPP_FOOBAR_EXE:WPProgram|My App FooBar|<MYAPP_EXTRAS_FOLDER>|EXENAME=((%{_bindir}/myapp-foobar.exe)) |
| 188 | %wps_object_create_end |
| 189 | |
| 190 | %postun |
| 191 | if [ "$1" -e 0 ]; then # (upon removal) |
| 192 | %wps_object_delete_all -n %{name}-extras |
| 193 | fi |
| 194 | }}} |
| 195 | |