diff --git a/LICENSES/GPL-2.0-or-later.txt b/LICENSES/GPL-2.0-or-later.txt new file mode 100644 index 0000000..1d80ac3 --- /dev/null +++ b/LICENSES/GPL-2.0-or-later.txt @@ -0,0 +1,319 @@ +GNU GENERAL PUBLIC LICENSE + +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. + +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your freedom to share +and change it. By contrast, the GNU General Public License is intended to +guarantee your freedom to share and change free software--to make sure the +software is free for all its users. This General Public License applies to +most of the Free Software Foundation's software and to any other program whose +authors commit to using it. (Some other Free Software Foundation software +is covered by the GNU Lesser General Public License instead.) You can apply +it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our +General Public Licenses are designed to make sure that you have the freedom +to distribute copies of free software (and charge for this service if you +wish), that you receive source code or can get it if you want it, that you +can change the software or use pieces of it in new free programs; and that +you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to +deny you these rights or to ask you to surrender the rights. These restrictions +translate to certain responsibilities for you if you distribute copies of +the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or +for a fee, you must give the recipients all the rights that you have. You +must make sure that they, too, receive or can get the source code. And you +must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) +offer you this license which gives you legal permission to copy, distribute +and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that +everyone understands that there is no warranty for this free software. If +the software is modified by someone else and passed on, we want its recipients +to know that what they have is not the original, so that any problems introduced +by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We +wish to avoid the danger that redistributors of a free program will individually +obtain patent licenses, in effect making the program proprietary. To prevent +this, we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification +follow. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains a notice +placed by the copyright holder saying it may be distributed under the terms +of this General Public License. The "Program", below, refers to any such program +or work, and a "work based on the Program" means either the Program or any +derivative work under copyright law: that is to say, a work containing the +Program or a portion of it, either verbatim or with modifications and/or translated +into another language. (Hereinafter, translation is included without limitation +in the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not covered +by this License; they are outside its scope. The act of running the Program +is not restricted, and the output from the Program is covered only if its +contents constitute a work based on the Program (independent of having been +made by running the Program). Whether that is true depends on what the Program +does. + +1. You may copy and distribute verbatim copies of the Program's source code +as you receive it, in any medium, provided that you conspicuously and appropriately +publish on each copy an appropriate copyright notice and disclaimer of warranty; +keep intact all the notices that refer to this License and to the absence +of any warranty; and give any other recipients of the Program a copy of this +License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you +may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, +thus forming a work based on the Program, and copy and distribute such modifications +or work under the terms of Section 1 above, provided that you also meet all +of these conditions: + +a) You must cause the modified files to carry prominent notices stating that +you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in whole or +in part contains or is derived from the Program or any part thereof, to be +licensed as a whole at no charge to all third parties under the terms of this +License. + +c) If the modified program normally reads commands interactively when run, +you must cause it, when started running for such interactive use in the most +ordinary way, to print or display an announcement including an appropriate +copyright notice and a notice that there is no warranty (or else, saying that +you provide a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this License. +(Exception: if the Program itself is interactive but does not normally print +such an announcement, your work based on the Program is not required to print +an announcement.) + +These requirements apply to the modified work as a whole. If identifiable +sections of that work are not derived from the Program, and can be reasonably +considered independent and separate works in themselves, then this License, +and its terms, do not apply to those sections when you distribute them as +separate works. But when you distribute the same sections as part of a whole +which is a work based on the Program, the distribution of the whole must be +on the terms of this License, whose permissions for other licensees extend +to the entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest your +rights to work written entirely by you; rather, the intent is to exercise +the right to control the distribution of derivative or collective works based +on the Program. + +In addition, mere aggregation of another work not based on the Program with +the Program (or with a work based on the Program) on a volume of a storage +or distribution medium does not bring the other work under the scope of this +License. + +3. You may copy and distribute the Program (or a work based on it, under Section +2) in object code or executable form under the terms of Sections 1 and 2 above +provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable source code, +which must be distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three years, to give +any third party, for a charge no more than your cost of physically performing +source distribution, a complete machine-readable copy of the corresponding +source code, to be distributed under the terms of Sections 1 and 2 above on +a medium customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer to distribute +corresponding source code. (This alternative is allowed only for noncommercial +distribution and only if you received the program in object code or executable +form with such an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for making +modifications to it. For an executable work, complete source code means all +the source code for all modules it contains, plus any associated interface +definition files, plus the scripts used to control compilation and installation +of the executable. However, as a special exception, the source code distributed +need not include anything that is normally distributed (in either source or +binary form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component itself +accompanies the executable. + +If distribution of executable or object code is made by offering access to +copy from a designated place, then offering equivalent access to copy the +source code from the same place counts as distribution of the source code, +even though third parties are not compelled to copy the source along with +the object code. + +4. You may not copy, modify, sublicense, or distribute the Program except +as expressly provided under this License. Any attempt otherwise to copy, modify, +sublicense or distribute the Program is void, and will automatically terminate +your rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses terminated +so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed +it. However, nothing else grants you permission to modify or distribute the +Program or its derivative works. These actions are prohibited by law if you +do not accept this License. Therefore, by modifying or distributing the Program +(or any work based on the Program), you indicate your acceptance of this License +to do so, and all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the Program), +the recipient automatically receives a license from the original licensor +to copy, distribute or modify the Program subject to these terms and conditions. +You may not impose any further restrictions on the recipients' exercise of +the rights granted herein. You are not responsible for enforcing compliance +by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent infringement +or for any other reason (not limited to patent issues), conditions are imposed +on you (whether by court order, agreement or otherwise) that contradict the +conditions of this License, they do not excuse you from the conditions of +this License. If you cannot distribute so as to satisfy simultaneously your +obligations under this License and any other pertinent obligations, then as +a consequence you may not distribute the Program at all. For example, if a +patent license would not permit royalty-free redistribution of the Program +by all those who receive copies directly or indirectly through you, then the +only way you could satisfy both it and this License would be to refrain entirely +from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply and +the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents +or other property right claims or to contest validity of any such claims; +this section has the sole purpose of protecting the integrity of the free +software distribution system, which is implemented by public license practices. +Many people have made generous contributions to the wide range of software +distributed through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing to +distribute software through any other system and a licensee cannot impose +that choice. + +This section is intended to make thoroughly clear what is believed to be a +consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain +countries either by patents or by copyrighted interfaces, the original copyright +holder who places the Program under this License may add an explicit geographical +distribution limitation excluding those countries, so that distribution is +permitted only in or among countries not thus excluded. In such case, this +License incorporates the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions of +the General Public License from time to time. Such new versions will be similar +in spirit to the present version, but may differ in detail to address new +problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies +a version number of this License which applies to it and "any later version", +you have the option of following the terms and conditions either of that version +or of any later version published by the Free Software Foundation. If the +Program does not specify a version number of this License, you may choose +any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs +whose distribution conditions are different, write to the author to ask for +permission. For software which is copyrighted by the Free Software Foundation, +write to the Free Software Foundation; we sometimes make exceptions for this. +Our decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing and reuse +of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR +THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE +STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM +"AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE +OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE +OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA +OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES +OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH +HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible +use to the public, the best way to achieve this is to make it free software +which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach +them to the start of each source file to most effectively convey the exclusion +of warranty; and each file should have at least the "copyright" line and a +pointer to where the full notice is found. + + + +Copyright (C) + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +Street, Fifth Floor, Boston, MA 02110-1301, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this when +it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author Gnomovision comes +with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, +and you are welcome to redistribute it under certain conditions; type `show +c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may be +called something other than `show w' and `show c'; they could even be mouse-clicks +or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your school, +if any, to sign a "copyright disclaimer" for the program, if necessary. Here +is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' +(which makes passes at compilers) written by James Hacker. + +, 1 April 1989 Ty Coon, President of Vice This General +Public License does not permit incorporating your program into proprietary +programs. If your program is a subroutine library, you may consider it more +useful to permit linking proprietary applications with the library. If this +is what you want to do, use the GNU Lesser General Public License instead +of this License. diff --git a/LICENSES/LGPL-2.0-only.txt b/LICENSES/LGPL-2.0-only.txt new file mode 100644 index 0000000..5c96471 --- /dev/null +++ b/LICENSES/LGPL-2.0-only.txt @@ -0,0 +1,446 @@ +GNU LIBRARY GENERAL PUBLIC LICENSE + +Version 2, June 1991 Copyright (C) 1991 Free Software Foundation, Inc. + +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is numbered 2 because +it goes with version 2 of the ordinary GPL.] + +Preamble + +The licenses for most software are designed to take away your freedom to share +and change it. By contrast, the GNU General Public Licenses are intended to +guarantee your freedom to share and change free software--to make sure the +software is free for all its users. + +This license, the Library General Public License, applies to some specially +designated Free Software Foundation software, and to any other libraries whose +authors decide to use it. You can use it for your libraries, too. + +When we speak of free software, we are referring to freedom, not price. Our +General Public Licenses are designed to make sure that you have the freedom +to distribute copies of free software (and charge for this service if you +wish), that you receive source code or can get it if you want it, that you +can change the software or use pieces of it in new free programs; and that +you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to +deny you these rights or to ask you to surrender the rights. These restrictions +translate to certain responsibilities for you if you distribute copies of +the library, or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for +a fee, you must give the recipients all the rights that we gave you. You must +make sure that they, too, receive or can get the source code. If you link +a program with the library, you must provide complete object files to the +recipients so that they can relink them with the library, after making changes +to the library and recompiling it. And you must show them these terms so they +know their rights. + +Our method of protecting your rights has two steps: (1) copyright the library, +and (2) offer you this license which gives you legal permission to copy, distribute +and/or modify the library. + +Also, for each distributor's protection, we want to make certain that everyone +understands that there is no warranty for this free library. If the library +is modified by someone else and passed on, we want its recipients to know +that what they have is not the original version, so that any problems introduced +by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We +wish to avoid the danger that companies distributing free software will individually +obtain patent licenses, thus in effect transforming the program into proprietary +software. To prevent this, we have made it clear that any patent must be licensed +for everyone's free use or not licensed at all. + +Most GNU software, including some libraries, is covered by the ordinary GNU +General Public License, which was designed for utility programs. This license, +the GNU Library General Public License, applies to certain designated libraries. +This license is quite different from the ordinary one; be sure to read it +in full, and don't assume that anything in it is the same as in the ordinary +license. + +The reason we have a separate public license for some libraries is that they +blur the distinction we usually make between modifying or adding to a program +and simply using it. Linking a program with a library, without changing the +library, is in some sense simply using the library, and is analogous to running +a utility program or application program. However, in a textual and legal +sense, the linked executable is a combined work, a derivative of the original +library, and the ordinary General Public License treats it as such. + +Because of this blurred distinction, using the ordinary General Public License +for libraries did not effectively promote software sharing, because most developers +did not use the libraries. We concluded that weaker conditions might promote +sharing better. + +However, unrestricted linking of non-free programs would deprive the users +of those programs of all benefit from the free status of the libraries themselves. +This Library General Public License is intended to permit developers of non-free +programs to use free libraries, while preserving your freedom as a user of +such programs to change the free libraries that are incorporated in them. +(We have not seen how to achieve this as regards changes in header files, +but we have achieved it as regards changes in the actual functions of the +Library.) The hope is that this will lead to faster development of free libraries. + +The precise terms and conditions for copying, distribution and modification +follow. Pay close attention to the difference between a "work based on the +library" and a "work that uses the library". The former contains code derived +from the library, while the latter only works together with the library. + +Note that it is possible for a library to be covered by the ordinary General +Public License rather than by this special one. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library which contains a +notice placed by the copyright holder or other authorized party saying it +may be distributed under the terms of this Library General Public License +(also called "this License"). Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data prepared +so as to be conveniently linked with application programs (which use some +of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has +been distributed under these terms. A "work based on the Library" means either +the Library or any derivative work under copyright law: that is to say, a +work containing the Library or a portion of it, either verbatim or with modifications +and/or translated straightforwardly into another language. (Hereinafter, translation +is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making modifications +to it. For a library, complete source code means all the source code for all +modules it contains, plus any associated interface definition files, plus +the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered +by this License; they are outside its scope. The act of running a program +using the Library is not restricted, and output from such a program is covered +only if its contents constitute a work based on the Library (independent of +the use of the Library in a tool for writing it). Whether that is true depends +on what the Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source +code as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and disclaimer +of warranty; keep intact all the notices that refer to this License and to +the absence of any warranty; and distribute a copy of this License along with +the Library. + +You may charge a fee for the physical act of transferring a copy, and you +may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, +thus forming a work based on the Library, and copy and distribute such modifications +or work under the terms of Section 1 above, provided that you also meet all +of these conditions: + + a) The modified work must itself be a software library. + +b) You must cause the files modified to carry prominent notices stating that +you changed the files and the date of any change. + +c) You must cause the whole of the work to be licensed at no charge to all +third parties under the terms of this License. + +d) If a facility in the modified Library refers to a function or a table of +data to be supplied by an application program that uses the facility, other +than as an argument passed when the facility is invoked, then you must make +a good faith effort to ensure that, in the event an application does not supply +such function or table, the facility still operates, and performs whatever +part of its purpose remains meaningful. + +(For example, a function in a library to compute square roots has a purpose +that is entirely well-defined independent of the application. Therefore, Subsection +2d requires that any application-supplied function or table used by this function +must be optional: if the application does not supply it, the square root function +must still compute square roots.) + +These requirements apply to the modified work as a whole. If identifiable +sections of that work are not derived from the Library, and can be reasonably +considered independent and separate works in themselves, then this License, +and its terms, do not apply to those sections when you distribute them as +separate works. But when you distribute the same sections as part of a whole +which is a work based on the Library, the distribution of the whole must be +on the terms of this License, whose permissions for other licensees extend +to the entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest your +rights to work written entirely by you; rather, the intent is to exercise +the right to control the distribution of derivative or collective works based +on the Library. + +In addition, mere aggregation of another work not based on the Library with +the Library (or with a work based on the Library) on a volume of a storage +or distribution medium does not bring the other work under the scope of this +License. + +3. You may opt to apply the terms of the ordinary GNU General Public License +instead of this License to a given copy of the Library. To do this, you must +alter all the notices that refer to this License, so that they refer to the +ordinary GNU General Public License, version 2, instead of to this License. +(If a newer version than version 2 of the ordinary GNU General Public License +has appeared, then you can specify that version instead if you wish.) Do not +make any other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, +so the ordinary GNU General Public License applies to all subsequent copies +and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library +into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of +it, under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you accompany it with the complete corresponding +machine-readable source code, which must be distributed under the terms of +Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a designated +place, then offering equivalent access to copy the source code from the same +place satisfies the requirement to distribute the source code, even though +third parties are not compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the Library, but +is designed to work with the Library by being compiled or linked with it, +is called a "work that uses the Library". Such a work, in isolation, is not +a derivative work of the Library, and therefore falls outside the scope of +this License. + +However, linking a "work that uses the Library" with the Library creates an +executable that is a derivative of the Library (because it contains portions +of the Library), rather than a "work that uses the library". The executable +is therefore covered by this License. Section 6 states terms for distribution +of such executables. + +When a "work that uses the Library" uses material from a header file that +is part of the Library, the object code for the work may be a derivative work +of the Library even though the source code is not. Whether this is true is +especially significant if the work can be linked without the Library, or if +the work is itself a library. The threshold for this to be true is not precisely +defined by law. + +If such an object file uses only numerical parameters, data structure layouts +and accessors, and small macros and small inline functions (ten lines or less +in length), then the use of the object file is unrestricted, regardless of +whether it is legally a derivative work. (Executables containing this object +code plus portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute +the object code for the work under the terms of Section 6. Any executables +containing that work also fall under Section 6, whether or not they are linked +directly with the Library itself. + +6. As an exception to the Sections above, you may also compile or link a "work +that uses the Library" with the Library to produce a work containing portions +of the Library, and distribute that work under terms of your choice, provided +that the terms permit modification of the work for the customer's own use +and reverse engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library +is used in it and that the Library and its use are covered by this License. +You must supply a copy of this License. If the work during execution displays +copyright notices, you must include the copyright notice for the Library among +them, as well as a reference directing the user to the copy of this License. +Also, you must do one of these things: + +a) Accompany the work with the complete corresponding machine-readable source +code for the Library including whatever changes were used in the work (which +must be distributed under Sections 1 and 2 above); and, if the work is an +executable linked with the Library, with the complete machine-readable "work +that uses the Library", as object code and/or source code, so that the user +can modify the Library and then relink to produce a modified executable containing +the modified Library. (It is understood that the user who changes the contents +of definitions files in the Library will not necessarily be able to recompile +the application to use the modified definitions.) + +b) Accompany the work with a written offer, valid for at least three years, +to give the same user the materials specified in Subsection 6a, above, for +a charge no more than the cost of performing this distribution. + +c) If distribution of the work is made by offering access to copy from a designated +place, offer equivalent access to copy the above specified materials from +the same place. + +d) Verify that the user has already received a copy of these materials or +that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must +include any data and utility programs needed for reproducing the executable +from it. However, as a special exception, the source code distributed need +not include anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the operating +system on which the executable runs, unless that component itself accompanies +the executable. + +It may happen that this requirement contradicts the license restrictions of +other proprietary libraries that do not normally accompany the operating system. +Such a contradiction means you cannot use both them and the Library together +in an executable that you distribute. + +7. You may place library facilities that are a work based on the Library side-by-side +in a single library together with other library facilities not covered by +this License, and distribute such a combined library, provided that the separate +distribution of the work based on the Library and of the other library facilities +is otherwise permitted, and provided that you do these two things: + +a) Accompany the combined library with a copy of the same work based on the +Library, uncombined with any other library facilities. This must be distributed +under the terms of the Sections above. + +b) Give prominent notice with the combined library of the fact that part of +it is a work based on the Library, and explaining where to find the accompanying +uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library +except as expressly provided under this License. Any attempt otherwise to +copy, modify, sublicense, link with, or distribute the Library is void, and +will automatically terminate your rights under this License. However, parties +who have received copies, or rights, from you under this License will not +have their licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed +it. However, nothing else grants you permission to modify or distribute the +Library or its derivative works. These actions are prohibited by law if you +do not accept this License. Therefore, by modifying or distributing the Library +(or any work based on the Library), you indicate your acceptance of this License +to do so, and all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), +the recipient automatically receives a license from the original licensor +to copy, distribute, link with or modify the Library subject to these terms +and conditions. You may not impose any further restrictions on the recipients' +exercise of the rights granted herein. You are not responsible for enforcing +compliance by third parties to this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement +or for any other reason (not limited to patent issues), conditions are imposed +on you (whether by court order, agreement or otherwise) that contradict the +conditions of this License, they do not excuse you from the conditions of +this License. If you cannot distribute so as to satisfy simultaneously your +obligations under this License and any other pertinent obligations, then as +a consequence you may not distribute the Library at all. For example, if a +patent license would not permit royalty-free redistribution of the Library +by all those who receive copies directly or indirectly through you, then the +only way you could satisfy both it and this License would be to refrain entirely +from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents +or other property right claims or to contest validity of any such claims; +this section has the sole purpose of protecting the integrity of the free +software distribution system which is implemented by public license practices. +Many people have made generous contributions to the wide range of software +distributed through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing to +distribute software through any other system and a licensee cannot impose +that choice. + +This section is intended to make thoroughly clear what is believed to be a +consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain +countries either by patents or by copyrighted interfaces, the original copyright +holder who places the Library under this License may add an explicit geographical +distribution limitation excluding those countries, so that distribution is +permitted only in or among countries not thus excluded. In such case, this +License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of +the Library General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to address +new problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies +a version number of this License which applies to it and "any later version", +you have the option of following the terms and conditions either of that version +or of any later version published by the Free Software Foundation. If the +Library does not specify a license version number, you may choose any version +ever published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs +whose distribution conditions are incompatible with these, write to the author +to ask for permission. For software which is copyrighted by the Free Software +Foundation, write to the Free Software Foundation; we sometimes make exceptions +for this. Our decision will be guided by the two goals of preserving the free +status of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR +THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE +STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY +"AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE +OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE +THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE +OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA +OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES +OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH +HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Libraries + +If you develop a new library, and you want it to be of the greatest possible +use to the public, we recommend making it free software that everyone can +redistribute and change. You can do so by permitting redistribution under +these terms (or, alternatively, under the terms of the ordinary General Public +License). + +To apply these terms, attach the following notices to the library. It is safest +to attach them to the start of each source file to most effectively convey +the exclusion of warranty; and each file should have at least the "copyright" +line and a pointer to where the full notice is found. + +one line to give the library's name and an idea of what it does. + +Copyright (C) year name of author + +This library is free software; you can redistribute it and/or modify it under +the terms of the GNU Library General Public License as published by the Free +Software Foundation; either version 2 of the License, or (at your option) +any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more +details. + +You should have received a copy of the GNU Library General Public License +along with this library; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your school, +if any, to sign a "copyright disclaimer" for the library, if necessary. Here +is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in + +the library `Frob' (a library for tweaking knobs) written + +by James Random Hacker. + +signature of Ty Coon, 1 April 1990 + +Ty Coon, President of Vice + +That's all there is to it! diff --git a/LICENSES/LGPL-2.0-or-later.txt b/LICENSES/LGPL-2.0-or-later.txt new file mode 100644 index 0000000..5c96471 --- /dev/null +++ b/LICENSES/LGPL-2.0-or-later.txt @@ -0,0 +1,446 @@ +GNU LIBRARY GENERAL PUBLIC LICENSE + +Version 2, June 1991 Copyright (C) 1991 Free Software Foundation, Inc. + +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is numbered 2 because +it goes with version 2 of the ordinary GPL.] + +Preamble + +The licenses for most software are designed to take away your freedom to share +and change it. By contrast, the GNU General Public Licenses are intended to +guarantee your freedom to share and change free software--to make sure the +software is free for all its users. + +This license, the Library General Public License, applies to some specially +designated Free Software Foundation software, and to any other libraries whose +authors decide to use it. You can use it for your libraries, too. + +When we speak of free software, we are referring to freedom, not price. Our +General Public Licenses are designed to make sure that you have the freedom +to distribute copies of free software (and charge for this service if you +wish), that you receive source code or can get it if you want it, that you +can change the software or use pieces of it in new free programs; and that +you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to +deny you these rights or to ask you to surrender the rights. These restrictions +translate to certain responsibilities for you if you distribute copies of +the library, or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for +a fee, you must give the recipients all the rights that we gave you. You must +make sure that they, too, receive or can get the source code. If you link +a program with the library, you must provide complete object files to the +recipients so that they can relink them with the library, after making changes +to the library and recompiling it. And you must show them these terms so they +know their rights. + +Our method of protecting your rights has two steps: (1) copyright the library, +and (2) offer you this license which gives you legal permission to copy, distribute +and/or modify the library. + +Also, for each distributor's protection, we want to make certain that everyone +understands that there is no warranty for this free library. If the library +is modified by someone else and passed on, we want its recipients to know +that what they have is not the original version, so that any problems introduced +by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We +wish to avoid the danger that companies distributing free software will individually +obtain patent licenses, thus in effect transforming the program into proprietary +software. To prevent this, we have made it clear that any patent must be licensed +for everyone's free use or not licensed at all. + +Most GNU software, including some libraries, is covered by the ordinary GNU +General Public License, which was designed for utility programs. This license, +the GNU Library General Public License, applies to certain designated libraries. +This license is quite different from the ordinary one; be sure to read it +in full, and don't assume that anything in it is the same as in the ordinary +license. + +The reason we have a separate public license for some libraries is that they +blur the distinction we usually make between modifying or adding to a program +and simply using it. Linking a program with a library, without changing the +library, is in some sense simply using the library, and is analogous to running +a utility program or application program. However, in a textual and legal +sense, the linked executable is a combined work, a derivative of the original +library, and the ordinary General Public License treats it as such. + +Because of this blurred distinction, using the ordinary General Public License +for libraries did not effectively promote software sharing, because most developers +did not use the libraries. We concluded that weaker conditions might promote +sharing better. + +However, unrestricted linking of non-free programs would deprive the users +of those programs of all benefit from the free status of the libraries themselves. +This Library General Public License is intended to permit developers of non-free +programs to use free libraries, while preserving your freedom as a user of +such programs to change the free libraries that are incorporated in them. +(We have not seen how to achieve this as regards changes in header files, +but we have achieved it as regards changes in the actual functions of the +Library.) The hope is that this will lead to faster development of free libraries. + +The precise terms and conditions for copying, distribution and modification +follow. Pay close attention to the difference between a "work based on the +library" and a "work that uses the library". The former contains code derived +from the library, while the latter only works together with the library. + +Note that it is possible for a library to be covered by the ordinary General +Public License rather than by this special one. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library which contains a +notice placed by the copyright holder or other authorized party saying it +may be distributed under the terms of this Library General Public License +(also called "this License"). Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data prepared +so as to be conveniently linked with application programs (which use some +of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has +been distributed under these terms. A "work based on the Library" means either +the Library or any derivative work under copyright law: that is to say, a +work containing the Library or a portion of it, either verbatim or with modifications +and/or translated straightforwardly into another language. (Hereinafter, translation +is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making modifications +to it. For a library, complete source code means all the source code for all +modules it contains, plus any associated interface definition files, plus +the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered +by this License; they are outside its scope. The act of running a program +using the Library is not restricted, and output from such a program is covered +only if its contents constitute a work based on the Library (independent of +the use of the Library in a tool for writing it). Whether that is true depends +on what the Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source +code as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and disclaimer +of warranty; keep intact all the notices that refer to this License and to +the absence of any warranty; and distribute a copy of this License along with +the Library. + +You may charge a fee for the physical act of transferring a copy, and you +may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, +thus forming a work based on the Library, and copy and distribute such modifications +or work under the terms of Section 1 above, provided that you also meet all +of these conditions: + + a) The modified work must itself be a software library. + +b) You must cause the files modified to carry prominent notices stating that +you changed the files and the date of any change. + +c) You must cause the whole of the work to be licensed at no charge to all +third parties under the terms of this License. + +d) If a facility in the modified Library refers to a function or a table of +data to be supplied by an application program that uses the facility, other +than as an argument passed when the facility is invoked, then you must make +a good faith effort to ensure that, in the event an application does not supply +such function or table, the facility still operates, and performs whatever +part of its purpose remains meaningful. + +(For example, a function in a library to compute square roots has a purpose +that is entirely well-defined independent of the application. Therefore, Subsection +2d requires that any application-supplied function or table used by this function +must be optional: if the application does not supply it, the square root function +must still compute square roots.) + +These requirements apply to the modified work as a whole. If identifiable +sections of that work are not derived from the Library, and can be reasonably +considered independent and separate works in themselves, then this License, +and its terms, do not apply to those sections when you distribute them as +separate works. But when you distribute the same sections as part of a whole +which is a work based on the Library, the distribution of the whole must be +on the terms of this License, whose permissions for other licensees extend +to the entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest your +rights to work written entirely by you; rather, the intent is to exercise +the right to control the distribution of derivative or collective works based +on the Library. + +In addition, mere aggregation of another work not based on the Library with +the Library (or with a work based on the Library) on a volume of a storage +or distribution medium does not bring the other work under the scope of this +License. + +3. You may opt to apply the terms of the ordinary GNU General Public License +instead of this License to a given copy of the Library. To do this, you must +alter all the notices that refer to this License, so that they refer to the +ordinary GNU General Public License, version 2, instead of to this License. +(If a newer version than version 2 of the ordinary GNU General Public License +has appeared, then you can specify that version instead if you wish.) Do not +make any other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, +so the ordinary GNU General Public License applies to all subsequent copies +and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library +into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of +it, under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you accompany it with the complete corresponding +machine-readable source code, which must be distributed under the terms of +Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a designated +place, then offering equivalent access to copy the source code from the same +place satisfies the requirement to distribute the source code, even though +third parties are not compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the Library, but +is designed to work with the Library by being compiled or linked with it, +is called a "work that uses the Library". Such a work, in isolation, is not +a derivative work of the Library, and therefore falls outside the scope of +this License. + +However, linking a "work that uses the Library" with the Library creates an +executable that is a derivative of the Library (because it contains portions +of the Library), rather than a "work that uses the library". The executable +is therefore covered by this License. Section 6 states terms for distribution +of such executables. + +When a "work that uses the Library" uses material from a header file that +is part of the Library, the object code for the work may be a derivative work +of the Library even though the source code is not. Whether this is true is +especially significant if the work can be linked without the Library, or if +the work is itself a library. The threshold for this to be true is not precisely +defined by law. + +If such an object file uses only numerical parameters, data structure layouts +and accessors, and small macros and small inline functions (ten lines or less +in length), then the use of the object file is unrestricted, regardless of +whether it is legally a derivative work. (Executables containing this object +code plus portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute +the object code for the work under the terms of Section 6. Any executables +containing that work also fall under Section 6, whether or not they are linked +directly with the Library itself. + +6. As an exception to the Sections above, you may also compile or link a "work +that uses the Library" with the Library to produce a work containing portions +of the Library, and distribute that work under terms of your choice, provided +that the terms permit modification of the work for the customer's own use +and reverse engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library +is used in it and that the Library and its use are covered by this License. +You must supply a copy of this License. If the work during execution displays +copyright notices, you must include the copyright notice for the Library among +them, as well as a reference directing the user to the copy of this License. +Also, you must do one of these things: + +a) Accompany the work with the complete corresponding machine-readable source +code for the Library including whatever changes were used in the work (which +must be distributed under Sections 1 and 2 above); and, if the work is an +executable linked with the Library, with the complete machine-readable "work +that uses the Library", as object code and/or source code, so that the user +can modify the Library and then relink to produce a modified executable containing +the modified Library. (It is understood that the user who changes the contents +of definitions files in the Library will not necessarily be able to recompile +the application to use the modified definitions.) + +b) Accompany the work with a written offer, valid for at least three years, +to give the same user the materials specified in Subsection 6a, above, for +a charge no more than the cost of performing this distribution. + +c) If distribution of the work is made by offering access to copy from a designated +place, offer equivalent access to copy the above specified materials from +the same place. + +d) Verify that the user has already received a copy of these materials or +that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must +include any data and utility programs needed for reproducing the executable +from it. However, as a special exception, the source code distributed need +not include anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the operating +system on which the executable runs, unless that component itself accompanies +the executable. + +It may happen that this requirement contradicts the license restrictions of +other proprietary libraries that do not normally accompany the operating system. +Such a contradiction means you cannot use both them and the Library together +in an executable that you distribute. + +7. You may place library facilities that are a work based on the Library side-by-side +in a single library together with other library facilities not covered by +this License, and distribute such a combined library, provided that the separate +distribution of the work based on the Library and of the other library facilities +is otherwise permitted, and provided that you do these two things: + +a) Accompany the combined library with a copy of the same work based on the +Library, uncombined with any other library facilities. This must be distributed +under the terms of the Sections above. + +b) Give prominent notice with the combined library of the fact that part of +it is a work based on the Library, and explaining where to find the accompanying +uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library +except as expressly provided under this License. Any attempt otherwise to +copy, modify, sublicense, link with, or distribute the Library is void, and +will automatically terminate your rights under this License. However, parties +who have received copies, or rights, from you under this License will not +have their licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed +it. However, nothing else grants you permission to modify or distribute the +Library or its derivative works. These actions are prohibited by law if you +do not accept this License. Therefore, by modifying or distributing the Library +(or any work based on the Library), you indicate your acceptance of this License +to do so, and all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), +the recipient automatically receives a license from the original licensor +to copy, distribute, link with or modify the Library subject to these terms +and conditions. You may not impose any further restrictions on the recipients' +exercise of the rights granted herein. You are not responsible for enforcing +compliance by third parties to this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement +or for any other reason (not limited to patent issues), conditions are imposed +on you (whether by court order, agreement or otherwise) that contradict the +conditions of this License, they do not excuse you from the conditions of +this License. If you cannot distribute so as to satisfy simultaneously your +obligations under this License and any other pertinent obligations, then as +a consequence you may not distribute the Library at all. For example, if a +patent license would not permit royalty-free redistribution of the Library +by all those who receive copies directly or indirectly through you, then the +only way you could satisfy both it and this License would be to refrain entirely +from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents +or other property right claims or to contest validity of any such claims; +this section has the sole purpose of protecting the integrity of the free +software distribution system which is implemented by public license practices. +Many people have made generous contributions to the wide range of software +distributed through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing to +distribute software through any other system and a licensee cannot impose +that choice. + +This section is intended to make thoroughly clear what is believed to be a +consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain +countries either by patents or by copyrighted interfaces, the original copyright +holder who places the Library under this License may add an explicit geographical +distribution limitation excluding those countries, so that distribution is +permitted only in or among countries not thus excluded. In such case, this +License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of +the Library General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to address +new problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies +a version number of this License which applies to it and "any later version", +you have the option of following the terms and conditions either of that version +or of any later version published by the Free Software Foundation. If the +Library does not specify a license version number, you may choose any version +ever published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs +whose distribution conditions are incompatible with these, write to the author +to ask for permission. For software which is copyrighted by the Free Software +Foundation, write to the Free Software Foundation; we sometimes make exceptions +for this. Our decision will be guided by the two goals of preserving the free +status of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR +THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE +STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY +"AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE +OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE +THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE +OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA +OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES +OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH +HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Libraries + +If you develop a new library, and you want it to be of the greatest possible +use to the public, we recommend making it free software that everyone can +redistribute and change. You can do so by permitting redistribution under +these terms (or, alternatively, under the terms of the ordinary General Public +License). + +To apply these terms, attach the following notices to the library. It is safest +to attach them to the start of each source file to most effectively convey +the exclusion of warranty; and each file should have at least the "copyright" +line and a pointer to where the full notice is found. + +one line to give the library's name and an idea of what it does. + +Copyright (C) year name of author + +This library is free software; you can redistribute it and/or modify it under +the terms of the GNU Library General Public License as published by the Free +Software Foundation; either version 2 of the License, or (at your option) +any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more +details. + +You should have received a copy of the GNU Library General Public License +along with this library; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your school, +if any, to sign a "copyright disclaimer" for the library, if necessary. Here +is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in + +the library `Frob' (a library for tweaking knobs) written + +by James Random Hacker. + +signature of Ty Coon, 1 April 1990 + +Ty Coon, President of Vice + +That's all there is to it! diff --git a/autotests/fallbackpackagetest.cpp b/autotests/fallbackpackagetest.cpp index 63b1283..6480b8b 100644 --- a/autotests/fallbackpackagetest.cpp +++ b/autotests/fallbackpackagetest.cpp @@ -1,74 +1,61 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* Copyright 2014 Marco Martin * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + SPDX-FileCopyrightText: 2014 Marco Martin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "fallbackpackagetest.h" #include #include #include "packagestructure.h" #include "packageloader.h" void FallbackPackageTest::initTestCase() { m_fallPackagePath = QFINDTESTDATA("data/testpackage"); m_fallbackPkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/Generic")); m_fallbackPkg.addFileDefinition("mainscript", QStringLiteral("ui/main.qml"), i18n("Main Script File")); m_fallbackPkg.setPath(m_fallPackagePath); m_packagePath = QFINDTESTDATA("data/testfallbackpackage"); m_pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/Generic")); m_pkg.addFileDefinition("mainscript", QStringLiteral("ui/main.qml"), i18n("Main Script File")); m_pkg.setPath(m_packagePath); } void FallbackPackageTest::beforeFallback() { QVERIFY(m_fallbackPkg.hasValidStructure()); QVERIFY(m_pkg.hasValidStructure()); //m_fallbackPkg should have otherfile.qml, m_pkg shouldn't QVERIFY(!m_fallbackPkg.filePath("ui", QStringLiteral("otherfile.qml")).isEmpty()); QVERIFY(m_pkg.filePath("ui", QStringLiteral("otherfile.qml")).isEmpty()); } void FallbackPackageTest::afterFallback() { m_pkg.setFallbackPackage(m_fallbackPkg); //after setting the fallback, m_pkg should resolve the exact same file as m_fallbackPkg // for otherfile.qml QVERIFY(!m_pkg.filePath("ui", QStringLiteral("otherfile.qml")).isEmpty()); QCOMPARE(m_fallbackPkg.filePath("ui", QStringLiteral("otherfile.qml")), m_pkg.filePath("ui", QStringLiteral("otherfile.qml"))); QVERIFY(m_fallbackPkg.filePath("mainscript") != m_pkg.filePath("mainscript")); } void FallbackPackageTest::cycle() { m_fallbackPkg.setFallbackPackage(m_pkg); m_pkg.setFallbackPackage(m_fallbackPkg); //The cycle should have been detected and filePath should take a not infinite time QTRY_COMPARE_WITH_TIMEOUT(m_fallbackPkg.filePath("ui", QStringLiteral("otherfile.qml")), m_pkg.filePath("ui", QStringLiteral("otherfile.qml")), 1000); } QTEST_MAIN(FallbackPackageTest) diff --git a/autotests/fallbackpackagetest.h b/autotests/fallbackpackagetest.h index 3b61994..02f16cf 100644 --- a/autotests/fallbackpackagetest.h +++ b/autotests/fallbackpackagetest.h @@ -1,46 +1,33 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* Copyright 2014 Marco Martin * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + SPDX-FileCopyrightText: 2014 Marco Martin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef FALLBACKPACKAGETEST_H #include #include "kpackage/package.h" class FallbackPackageTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void beforeFallback(); void afterFallback(); void cycle(); private: KPackage::Package m_pkg; KPackage::Package m_fallbackPkg; QString m_packagePath; QString m_fallPackagePath; }; #endif diff --git a/autotests/mockdepresolver/main.cpp b/autotests/mockdepresolver/main.cpp index 52e6921..50ef52e 100644 --- a/autotests/mockdepresolver/main.cpp +++ b/autotests/mockdepresolver/main.cpp @@ -1,56 +1,43 @@ -/****************************************************************************** -* Copyright 2016 Bhushan Shah * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2016 Bhushan Shah + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include #include #include int main(int argc, char** argv) { QCoreApplication app(argc, argv); Q_ASSERT(app.arguments().count() == 2); const QUrl url(app.arguments().constLast()); Q_ASSERT(url.isValid()); Q_ASSERT(url.scheme() == QLatin1String("mock")); // This is very basic dep resolver used for mocking in tests // if asked to install invalidapp, will fail // if asked to install validdep, will pass const QString componentName = url.host(); if (componentName.isEmpty()) { qWarning() << "wrongly formatted URI" << url; return 1; } if (componentName == QStringLiteral("invaliddep")) { qWarning() << "package asked to install invalid dep, bailing out"; return 1; } if (componentName.startsWith(QLatin1String("validdep"))) { qWarning() << "asked to install valid dep, success!"; return 0; } qWarning() << "Assuming provided package is not available"; return 1; } diff --git a/autotests/packagestructuretest.cpp b/autotests/packagestructuretest.cpp index 556cdb2..db4b9b2 100644 --- a/autotests/packagestructuretest.cpp +++ b/autotests/packagestructuretest.cpp @@ -1,368 +1,355 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* Copyright 2014 by Marco Martin * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + SPDX-FileCopyrightText: 2014 Marco Martin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "packagestructuretest.h" #include #include #include "packagestructure.h" #include "packageloader.h" class NoPrefixes : public KPackage::Package { public: explicit NoPrefixes() : KPackage::Package(new KPackage::PackageStructure) { setContentsPrefixPaths(QStringList()); addDirectoryDefinition("bin", QStringLiteral("bin"), QStringLiteral("bin")); addFileDefinition("MultiplePaths", QStringLiteral("first"), QStringLiteral("Description proper")); addFileDefinition("MultiplePaths", QStringLiteral("second"), QStringLiteral("Description proper")); setPath(QStringLiteral("/")); } }; class Wallpaper : public KPackage::PackageStructure { Q_OBJECT public: void initPackage(KPackage::Package *package) override { package->addDirectoryDefinition("images", QStringLiteral("images/"), i18n("Images")); QStringList mimetypes; mimetypes << QStringLiteral("image/svg") << QStringLiteral("image/png") << QStringLiteral("image/jpeg") << QStringLiteral("image/jpg"); package->setMimeTypes("images", mimetypes); package->setRequired("images", true); package->addFileDefinition("screenshot", QStringLiteral("screenshot.png"), i18n("Screenshot")); package->setAllowExternalPaths(true); } void pathChanged(KPackage::Package *package) override { static bool guard = false; if (guard) { return; } guard = true; QString ppath = package->path(); if (ppath.endsWith('/')) { ppath.chop(1); if (!QFile::exists(ppath)) { ppath = package->path(); } } QFileInfo info(ppath); const bool isFullPackage = info.isDir(); package->removeDefinition("preferred"); package->setRequired("images", isFullPackage); if (isFullPackage) { package->setContentsPrefixPaths(QStringList() << QStringLiteral("contents/")); } else { package->addFileDefinition("screenshot", info.fileName(), i18n("Preview")); package->addFileDefinition("preferred", info.fileName(), QString()); package->setContentsPrefixPaths(QStringList()); package->setPath(info.path()); } guard = false; } }; class SimpleContent : public KPackage::PackageStructure { Q_OBJECT public: void initPackage(KPackage::Package *package) override { package->addDirectoryDefinition("ui", QStringLiteral("ui/"), i18n("User interface")); } void pathChanged(KPackage::Package *package) override { if (!package->metadata().isValid()) { return; } if (package->metadata().serviceTypes().contains(QStringLiteral("CustomContent"))) { package->addFileDefinition("customcontentfile", QStringLiteral("customcontent/CustomContentFile.qml"), i18n("Custom file only for packages that contain CustomContent in their servicetypes")); } else { package->removeDefinition("customcontentfile"); } } }; void PackageStructureTest::initTestCase() { m_packagePath = QFINDTESTDATA("data/testpackage"); ps = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/Generic")); ps.addFileDefinition("mainscript", QStringLiteral("ui/main.qml"), i18n("Main Script File")); ps.setPath(m_packagePath); } void PackageStructureTest::validStructures() { QVERIFY(ps.hasValidStructure()); QVERIFY(!KPackage::Package().hasValidStructure()); QVERIFY(!KPackage::PackageLoader::self()->loadPackage(QStringLiteral("doesNotExist")).hasValidStructure()); } void PackageStructureTest::validPackages() { QVERIFY(ps.isValid()); QVERIFY(!KPackage::Package().isValid()); QVERIFY(!KPackage::PackageLoader::self()->loadPackage(QStringLiteral("doesNotExist")).isValid()); QVERIFY(NoPrefixes().isValid()); KPackage::Package p = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/Generic")); p.addFileDefinition("mainscript", QStringLiteral("ui/main.qml"), i18n("Main Script File")); QVERIFY(!p.isValid()); p.setPath(QStringLiteral("/does/not/exist")); QVERIFY(!p.isValid()); p.setPath(ps.path()); QVERIFY(p.isValid()); } void PackageStructureTest::wallpaperPackage() { KPackage::Package p(new Wallpaper); p.setPath(m_packagePath); QVERIFY(p.isValid()); KPackage::Package p2(new Wallpaper); p2.setPath(m_packagePath + "/contents/images/empty.png"); QVERIFY(p2.isValid()); } void PackageStructureTest::copyPerformance() { // seed the cache first ps.filePath("mainscript"); QBENCHMARK { KPackage::Package foo(ps); const QString bar = foo.filePath("mainscript"); Q_UNUSED(bar); } } void PackageStructureTest::mutateAfterCopy() { const bool mainscriptRequired = ps.isRequired("mainscript"); const QStringList imageMimeTypes = ps.mimeTypes("images"); const QStringList defaultMimeTypes = ps.mimeTypes("translations"); const QString packageRoot = ps.defaultPackageRoot(); const bool externalPaths = ps.allowExternalPaths(); const QStringList contentsPrefixPaths = ps.contentsPrefixPaths(); const QList files = ps.files(); const QList dirs = ps.directories(); KPackage::Package copy(ps); copy.setRequired("mainscript", !mainscriptRequired); QCOMPARE(ps.isRequired("mainscript"), mainscriptRequired); QCOMPARE(copy.isRequired("mainscript"), !mainscriptRequired); copy = ps; const QString copyPackageRoot = packageRoot + "more/"; copy.setDefaultPackageRoot(copyPackageRoot); QCOMPARE(ps.defaultPackageRoot(), packageRoot); QCOMPARE(copy.defaultPackageRoot(), copyPackageRoot); copy = ps; copy.setAllowExternalPaths(!externalPaths); QCOMPARE(ps.allowExternalPaths(), externalPaths); QCOMPARE(copy.allowExternalPaths(), !externalPaths); copy = ps; QStringList copyContentsPrefixPaths = contentsPrefixPaths; copyContentsPrefixPaths << QStringLiteral("more/"); copy.setContentsPrefixPaths(copyContentsPrefixPaths); QCOMPARE(ps.contentsPrefixPaths(), contentsPrefixPaths); QCOMPARE(copy.contentsPrefixPaths(), copyContentsPrefixPaths); copy = ps; copy.addFileDefinition("nonsense", QStringLiteral("foobar"), QString()); QCOMPARE(ps.files(), files); QVERIFY(ps.files() != copy.files()); copy = ps; copy.addDirectoryDefinition("nonsense", QStringLiteral("foobar"), QString()); QCOMPARE(ps.directories(), dirs); QVERIFY(ps.directories() != copy.directories()); copy = ps; copy.removeDefinition("mainscript"); QCOMPARE(ps.files(), files); QVERIFY(ps.files() != copy.files()); copy = ps; QVERIFY(!imageMimeTypes.isEmpty()); QStringList copyMimeTypes; copyMimeTypes << imageMimeTypes.first(); copy.setMimeTypes("images", copyMimeTypes); QCOMPARE(ps.mimeTypes("images"), imageMimeTypes); QCOMPARE(copy.mimeTypes("images"), copyMimeTypes); copy = ps; QStringList copyDefaultMimeTypes = defaultMimeTypes; copyDefaultMimeTypes << QStringLiteral("rubbish"); copy.setDefaultMimeTypes(copyDefaultMimeTypes); QCOMPARE(ps.mimeTypes("translations"), defaultMimeTypes); QCOMPARE(copy.mimeTypes("translations"), copyDefaultMimeTypes); } void PackageStructureTest::emptyContentsPrefix() { NoPrefixes package; QString path(package.filePath("bin", QStringLiteral("ls"))); //qDebug() << path; QCOMPARE(path, QStringLiteral("/bin/ls")); } void PackageStructureTest::multiplePaths() { NoPrefixes package; QCOMPARE(package.name("MultiplePaths"), QStringLiteral("Description proper")); } void PackageStructureTest::directories() { QList dirs; dirs << "config" << "data" << "images" << "theme" << "scripts" << "translations" << "ui"; const QList psDirs = ps.directories(); QCOMPARE(dirs.count(), psDirs.count()); for (const char *dir : psDirs) { bool found = false; for (const char *check : qAsConst(dirs)) { if (qstrcmp(dir, check)) { found = true; break; } } QVERIFY(found); } for (const char *dir : qAsConst(dirs)) { bool found = false; for (const char *check : psDirs) { if (qstrcmp(dir, check)) { found = true; break; } } QVERIFY(found); } } void PackageStructureTest::requiredDirectories() { QList dirs; QCOMPARE(ps.requiredDirectories(), dirs); } void PackageStructureTest::files() { QList files; files << "mainconfigui" << "mainconfigxml" << "mainscript"; const QList psFiles = ps.files(); //for (int i = 0; i < psFiles.count(); ++i) { // qDebug() << psFiles[i]; //} for (const char *file : psFiles) { bool found = false; for (const char *check : qAsConst(files)) { if (qstrcmp(file, check)) { found = true; break; } } QVERIFY(found); } } void PackageStructureTest::requiredFiles() { QList files; files << "mainscript"; QList psFiles = ps.requiredFiles(); QCOMPARE(files.count(), psFiles.count()); for (int i = 0; i < files.count(); ++i) { QCOMPARE(files[i], psFiles[i]); } } void PackageStructureTest::path() { QCOMPARE(ps.filePath("images"), QDir(m_packagePath + QLatin1String("/contents/images")).canonicalPath()); QCOMPARE(ps.filePath("theme"), QDir(m_packagePath + QLatin1String("/contents/theme")).canonicalPath()); QCOMPARE(ps.filePath("mainscript"), QFileInfo(m_packagePath + QLatin1String("/contents/ui/main.qml")).canonicalFilePath()); } void PackageStructureTest::name() { QCOMPARE(ps.name("config"), i18n("Configuration Definitions")); QCOMPARE(ps.name("mainscript"), i18n("Main Script File")); } void PackageStructureTest::required() { QVERIFY(ps.isRequired("mainscript")); } void PackageStructureTest::mimeTypes() { QStringList mimeTypes; mimeTypes << QStringLiteral("image/svg+xml") << QStringLiteral("image/png") << QStringLiteral("image/jpeg"); QCOMPARE(ps.mimeTypes("images"), mimeTypes); QCOMPARE(ps.mimeTypes("theme"), mimeTypes); } void PackageStructureTest::customContent() { KPackage::Package p(new SimpleContent); p.setPath(QFINDTESTDATA("data/simplecontent")); QVERIFY(p.isValid()); QCOMPARE(p.filePath("customcontentfile"), QString()); p.setPath(QFINDTESTDATA("data/customcontent")); const QString expected = QFINDTESTDATA("data/customcontent") + "/contents/customcontent/CustomContentFile.qml"; QCOMPARE(p.filePath("customcontentfile"), expected); QVERIFY(p.isValid()); p.setPath(QFINDTESTDATA("data/simplecontent")); QVERIFY(p.isValid()); QCOMPARE(p.filePath("customcontentfile"), QString()); } QTEST_MAIN(PackageStructureTest) #include "packagestructuretest.moc" diff --git a/autotests/packagestructuretest.h b/autotests/packagestructuretest.h index 68c9c62..f33d609 100644 --- a/autotests/packagestructuretest.h +++ b/autotests/packagestructuretest.h @@ -1,56 +1,43 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* Copyright 2014 by Marco Martin * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + SPDX-FileCopyrightText: 2014 Marco Martin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef PACKAGESTRUCTURETEST_H #include #include "kpackage/package.h" class PackageStructureTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void validStructures(); void validPackages(); void wallpaperPackage(); void copyPerformance(); void mutateAfterCopy(); void emptyContentsPrefix(); void multiplePaths(); void directories(); void requiredDirectories(); void files(); void requiredFiles(); void path(); void name(); void required(); void mimeTypes(); void customContent(); private: KPackage::Package ps; QString m_packagePath; }; #endif diff --git a/autotests/plasmoidpackagetest.cpp b/autotests/plasmoidpackagetest.cpp index f7afdfc..d0558a9 100644 --- a/autotests/plasmoidpackagetest.cpp +++ b/autotests/plasmoidpackagetest.cpp @@ -1,445 +1,432 @@ -/****************************************************************************** -* Copyright 2007 by Bertjan Broeksema * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Bertjan Broeksema + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "plasmoidpackagetest.h" #include "../src/kpackage/config-package.h" #include "../src/kpackage/private/versionparser.cpp" #include #include #include #include #include #include #include #include "packageloader.h" #include "plasmoidstructure.h" void PlasmoidPackageTest::initTestCase() { QStandardPaths::setTestModeEnabled(true); } void PlasmoidPackageTest::init() { qDebug() << "PlasmoidPackage::init()"; m_package = QStringLiteral("Package"); m_packageRoot = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/packageRoot"; m_defaultPackage = KPackage::Package(new KPackage::PlasmoidPackage); cleanup(); // to prevent previous runs from interfering with this one } void PlasmoidPackageTest::cleanup() { qDebug() << "cleaning up"; // Clean things up. QDir(m_packageRoot).removeRecursively(); } void PlasmoidPackageTest::createTestPackage(const QString &packageName, const QString &version) { qDebug() << "Create test package" << m_packageRoot; QDir pRoot(m_packageRoot); // Create the root and package dir. if (!pRoot.exists()) { QVERIFY(QDir().mkpath(m_packageRoot)); } // Create the package dir QVERIFY(QDir().mkpath(m_packageRoot + "/" + packageName)); qDebug() << "Created" << (m_packageRoot + "/" + packageName); // Create the metadata.desktop file QFile file(m_packageRoot + "/" + packageName + "/metadata.desktop"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream out(&file); out << "[Desktop Entry]\n"; out << "Name=" << packageName << "\n"; out << "X-KDE-PluginInfo-Name=" << packageName << "\n"; out << "X-KDE-PluginInfo-Version=" << version << "\n"; file.flush(); file.close(); qDebug() << "OUT: " << packageName; // Create the ui dir. QVERIFY(QDir().mkpath(m_packageRoot + "/" + packageName + "/contents/ui")); // Create the main file. file.setFileName(m_packageRoot + "/" + packageName + "/contents/ui/main.qml"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); out << "THIS IS A PLASMOID SCRIPT....."; file.flush(); file.close(); qDebug() << "THIS IS A PLASMOID SCRIPT THING"; // Now we have a minimal plasmoid package which is valid. Let's add some // files to it for test purposes. // Create the images dir. QVERIFY(QDir().mkpath(m_packageRoot + "/" + packageName + "/contents/images")); file.setFileName(m_packageRoot + "/" + packageName + "/contents/images/image-1.svg"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); out << "This is a test image"; file.flush(); file.close(); file.setFileName(m_packageRoot + "/" + packageName + "/contents/images/image-2.svg"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); out.setDevice(&file); out << "This is another test image"; file.flush(); file.close(); // Create the scripts dir. QVERIFY(QDir().mkpath(m_packageRoot + "/" + packageName + "/contents/code")); // Create 2 js files file.setFileName(m_packageRoot + "/" + packageName + "/contents/code/script.js"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); out << "THIS IS A SCRIPT....."; file.flush(); file.close(); } void PlasmoidPackageTest::isValid() { KPackage::Package *p = new KPackage::Package(m_defaultPackage); p->setPath(m_packageRoot + '/' + m_package); #ifndef NDEBUG qDebug() << "package path is" << p->path(); #endif // A PlasmoidPackage is valid when: // - The package root exists. // - The package root consists an file named "ui/main.qml" QVERIFY(!p->isValid()); // Create the root and package dir. QVERIFY(QDir().mkpath(m_packageRoot)); QVERIFY(QDir().mkpath(m_packageRoot + "/" + m_package)); // Should still be invalid. delete p; p = new KPackage::Package(m_defaultPackage); p->setPath(m_packageRoot + '/' + m_package); QVERIFY(!p->isValid()); // Create the metadata.desktop file. QFile file(m_packageRoot + "/" + m_package + "/metadata.desktop"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream out(&file); out << "[Desktop Entry]\n"; out << "Name=test\n"; out << "Description=Just a test desktop file"; file.flush(); file.close(); // Create the ui dir. QVERIFY(QDir().mkpath(m_packageRoot + "/" + m_package + "/contents/ui")); // No main file yet so should still be invalid. delete p; p = new KPackage::Package(m_defaultPackage); p->setPath(m_packageRoot + '/' + m_package); QVERIFY(!p->isValid()); // Create the main file. file.setFileName(m_packageRoot + "/" + m_package + "/contents/ui/main.qml"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); out.setDevice(&file); out << "THIS IS A PLASMOID SCRIPT.....\n"; file.flush(); file.close(); file.setPermissions(QFile::ReadUser | QFile::WriteUser); // Main file exists so should be valid now. delete p; p = new KPackage::Package(m_defaultPackage); p->setPath(m_packageRoot + '/' + m_package); QVERIFY(p->isValid()); #if KPACKAGE_ENABLE_DEPRECATED_SINCE(5, 21) QCOMPARE(p->contentsHash(), QStringLiteral("a41160c6a763ea505c95bee12a7fc87952a61cf1")); #endif QCOMPARE(p->cryptographicHash(QCryptographicHash::Sha1), QByteArrayLiteral("a41160c6a763ea505c95bee12a7fc87952a61cf1")); delete p; } void PlasmoidPackageTest::filePath() { return; // Package::filePath() returns // - {package_root}/{package_name}/path/to/file if the file exists // - QString() otherwise. KPackage::Package *p = new KPackage::Package(m_defaultPackage); p->setPath(m_packageRoot + '/' + m_package); QCOMPARE(p->filePath("scripts", QStringLiteral("main")), QString()); QVERIFY(QDir().mkpath(m_packageRoot + "/" + m_package + "/contents/ui/main.qml")); QFile file(m_packageRoot + "/" + m_package + "/contents/ui/main.qml"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream out(&file); out << "THIS IS A PLASMOID SCRIPT....."; file.flush(); file.close(); // The package is valid by now so a path for code/main should get returned. delete p; p = new KPackage::Package(m_defaultPackage); p->setPath(m_packageRoot + '/' + m_package); const QString path = QFileInfo(m_packageRoot + "/" + m_package + "/contents/ui/main.qml").canonicalFilePath(); // Two ways to get the same info. // 1. Give the file type which refers to a class of files (a directory) in // the package structure and the file name. // 2. Give the file type which refers to a file in the package structure. // // NOTE: scripts, main and mainscript are defined in packages.cpp and are // specific for a PlasmoidPackage. QCOMPARE(p->filePath("scripts", QStringLiteral("main")), path); QCOMPARE(p->filePath("mainscript"), path); delete p; } void PlasmoidPackageTest::entryList() { // Create a package named @p packageName which is valid and has some images. createTestPackage(m_package, QStringLiteral("1.1")); // Create a package object and verify that it is valid. KPackage::Package *p = new KPackage::Package(m_defaultPackage); p->setPath(m_packageRoot + '/' + m_package); QVERIFY(p->isValid()); // Now we have a valid package that should contain the following files in // given filetypes: // fileTye - Files // scripts - {"script.js"} // images - {"image-1.svg", "image-2.svg"} QStringList files = p->entryList("scripts"); QCOMPARE(files.size(), 1); QVERIFY(files.contains(QStringLiteral("script.js"))); files = p->entryList("images"); QCOMPARE(files.size(), 2); QVERIFY(files.contains(QStringLiteral("image-1.svg"))); QVERIFY(files.contains(QStringLiteral("image-2.svg"))); delete p; } void PlasmoidPackageTest::createAndInstallPackage() { qDebug() << " "; qDebug() << " CreateAndInstall "; createTestPackage(QStringLiteral("plasmoid_to_package"), QStringLiteral("1.1")); const QString packagePath = m_packageRoot + '/' + "testpackage.plasmoid"; KZip creator(packagePath); QVERIFY(creator.open(QIODevice::WriteOnly)); creator.addLocalDirectory(m_packageRoot + '/' + "plasmoid_to_package", QStringLiteral(".")); creator.close(); QDir rootDir(m_packageRoot + "/plasmoid_to_package"); rootDir.removeRecursively(); QVERIFY2(QFile::exists(packagePath), qPrintable(packagePath)); KZip package(packagePath); QVERIFY(package.open(QIODevice::ReadOnly)); const KArchiveDirectory *dir = package.directory(); QVERIFY(dir);// QVERIFY(dir->entry(QStringLiteral("metadata.desktop"))); const KArchiveEntry *contentsEntry = dir->entry(QStringLiteral("contents")); QVERIFY(contentsEntry); QVERIFY(contentsEntry->isDirectory()); const KArchiveDirectory *contents = static_cast(contentsEntry); QVERIFY(contents->entry(QStringLiteral("ui"))); QVERIFY(contents->entry(QStringLiteral("images"))); m_defaultPackageStructure = new KPackage::PackageStructure(this); KPackage::Package *p = new KPackage::Package(m_defaultPackageStructure); qDebug() << "Installing " << packagePath; //const QString packageRoot = "plasma/plasmoids/"; //const QString servicePrefix = "plasma-applet-"; KJob *job = p->install(packagePath, m_packageRoot); connect(job, SIGNAL(finished(KJob*)), SLOT(packageInstalled(KJob*))); QSignalSpy spy(job, SIGNAL(finished(KJob*))); QVERIFY(spy.wait(1000)); //is the package instance usable (ie proper path) after the install job has been completed? QCOMPARE(p->path(), QString(QDir(m_packageRoot % "/plasmoid_to_package").canonicalPath() + QLatin1Char('/'))); cleanupPackage(QStringLiteral("plasmoid_to_package")); //QVERIFY(p->isValid()); delete p; } void PlasmoidPackageTest::noCrashOnAsyncInstall() { createTestPackage(QStringLiteral("plasmoid_to_package"), QStringLiteral("1.1")); const QString packagePath = m_packageRoot + '/' + "testpackage.plasmoid"; KZip creator(packagePath); QVERIFY(creator.open(QIODevice::WriteOnly)); creator.addLocalDirectory(m_packageRoot + '/' + "plasmoid_to_package", QStringLiteral(".")); creator.close(); QDir rootDir(m_packageRoot + "/plasmoid_to_package"); rootDir.removeRecursively(); KJob *job; //scope the package so it will get deleted before the install operation finishes //package is explicitlyshared internally and designed to be used on the stack //see #370718 { KPackage::Package package(new KPackage::PackageStructure(this)); job = package.install(packagePath, m_packageRoot); } connect(job, SIGNAL(finished(KJob*)), SLOT(packageInstalled(KJob*))); QSignalSpy spy(job, SIGNAL(finished(KJob*))); QVERIFY(spy.wait(1000)); cleanupPackage(QStringLiteral("plasmoid_to_package")); } void PlasmoidPackageTest::createAndUpdatePackage() { //does the version number parsing work? QVERIFY(KPackage::isVersionNewer(QStringLiteral("1.1"), QStringLiteral("1.1.1"))); QVERIFY(!KPackage::isVersionNewer(QStringLiteral("1.1.1"), QStringLiteral("1.1"))); QVERIFY(KPackage::isVersionNewer(QStringLiteral("1.1.1"), QStringLiteral("1.1.2"))); QVERIFY(KPackage::isVersionNewer(QStringLiteral("1.1.2"), QStringLiteral("2.1"))); QVERIFY(KPackage::isVersionNewer(QStringLiteral("0.1.2"), QStringLiteral("2"))); QVERIFY(!KPackage::isVersionNewer(QStringLiteral("1"), QStringLiteral("0.1.2"))); qDebug() << " "; qDebug() << " CreateAndUpdate "; createTestPackage(QStringLiteral("plasmoid_to_package"), QStringLiteral("1.1")); const QString packagePath = m_packageRoot + '/' + "testpackage.plasmoid"; KZip creator(packagePath); QVERIFY(creator.open(QIODevice::WriteOnly)); creator.addLocalDirectory(m_packageRoot + '/' + "plasmoid_to_package", QStringLiteral(".")); creator.close(); QDir rootDir(m_packageRoot + "/plasmoid_to_package"); rootDir.removeRecursively(); QVERIFY(QFile::exists(packagePath)); KZip package(packagePath); QVERIFY(package.open(QIODevice::ReadOnly)); const KArchiveDirectory *dir = package.directory(); QVERIFY(dir);// QVERIFY(dir->entry(QStringLiteral("metadata.desktop"))); const KArchiveEntry *contentsEntry = dir->entry(QStringLiteral("contents")); QVERIFY(contentsEntry); QVERIFY(contentsEntry->isDirectory()); const KArchiveDirectory *contents = static_cast(contentsEntry); QVERIFY(contents->entry(QStringLiteral("ui"))); QVERIFY(contents->entry(QStringLiteral("images"))); m_defaultPackageStructure = new KPackage::PackageStructure(this); KPackage::Package *p = new KPackage::Package(m_defaultPackageStructure); qDebug() << "Installing " << packagePath; //const QString packageRoot = "plasma/plasmoids/"; //const QString servicePrefix = "plasma-applet-"; KJob *job = p->update(packagePath, m_packageRoot); connect(job, SIGNAL(finished(KJob*)), SLOT(packageInstalled(KJob*))); QSignalSpy spy(job, SIGNAL(finished(KJob*))); QVERIFY(spy.wait(1000)); //same version, should fail job = p->update(packagePath, m_packageRoot); QSignalSpy spyFail(job, SIGNAL(finished(KJob*))); QVERIFY(spyFail.wait(1000)); QVERIFY(job->error() == KPackage::Package::JobError::NewerVersionAlreadyInstalledError); qDebug()<errorText(); //create a new package with higher version createTestPackage(QStringLiteral("plasmoid_to_package"), QStringLiteral("1.2")); KZip creator2(packagePath); QVERIFY(creator2.open(QIODevice::WriteOnly)); creator2.addLocalDirectory(m_packageRoot + '/' + "plasmoid_to_package", QStringLiteral(".")); creator2.close(); QDir rootDir2(m_packageRoot + "/plasmoid_to_package"); rootDir2.removeRecursively(); KJob *job2 = p->update(packagePath, m_packageRoot); connect(job2, SIGNAL(finished(KJob*)), SLOT(packageInstalled(KJob*))); QSignalSpy spy2(job2, SIGNAL(finished(KJob*))); QVERIFY(spy2.wait(1000)); cleanupPackage(QStringLiteral("plasmoid_to_package")); //QVERIFY(p->isValid()); delete p; } void PlasmoidPackageTest::uncompressPackageWithSubFolder() { KPackage::PackageStructure *structure = new KPackage::PackageStructure; KPackage::Package package(structure); package.setPath(QFINDTESTDATA("data/customcontent.tar.gz")); //if metadata is correctly found, servicetypes should be ("SimpleContent", "CustomContent") QCOMPARE(package.metadata().serviceTypes(), QStringList({"SimpleContent", "CustomContent"})); } void PlasmoidPackageTest::cleanupPackage(const QString &packageName) { KPackage::Package *p = new KPackage::Package(m_defaultPackageStructure); KJob *jj = p->uninstall(packageName, m_packageRoot); connect(jj, SIGNAL(finished(KJob*)), SLOT(packageUninstalled(KJob*))); QSignalSpy spy(jj, &KJob::finished); QVERIFY(spy.wait(1000)); } void PlasmoidPackageTest::packageInstalled(KJob *j) { QVERIFY2(j->error() == KJob::NoError, qPrintable(j->errorText())); } void PlasmoidPackageTest::packageUninstalled(KJob *j) { QVERIFY2(j->error() == KJob::NoError, qPrintable(j->errorText())); } QTEST_MAIN(PlasmoidPackageTest) diff --git a/autotests/plasmoidpackagetest.h b/autotests/plasmoidpackagetest.h index a6e9a8e..e932323 100644 --- a/autotests/plasmoidpackagetest.h +++ b/autotests/plasmoidpackagetest.h @@ -1,60 +1,47 @@ -/****************************************************************************** -* Copyright 2007 by Bertjan Broeksema * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Bertjan Broeksema + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef PACKAGETEST_H #include #include "kpackage/package.h" #include "kpackage/packagestructure.h" class PlasmoidPackageTest : public QObject { Q_OBJECT public Q_SLOTS: void initTestCase(); void init(); void cleanup(); private Q_SLOTS: void createAndInstallPackage(); void createAndUpdatePackage(); void uncompressPackageWithSubFolder(); void isValid(); void filePath(); void entryList(); void noCrashOnAsyncInstall(); void packageInstalled(KJob *j); void packageUninstalled(KJob *j); private: void createTestPackage(const QString &packageName, const QString &version); void cleanupPackage(const QString &packageName); QString m_packageRoot; QString m_package; KJob *m_packageJob; KPackage::Package m_defaultPackage; KPackage::PackageStructure *m_defaultPackageStructure; }; #endif diff --git a/autotests/plasmoidstructure.cpp b/autotests/plasmoidstructure.cpp index a282379..ad94fbc 100644 --- a/autotests/plasmoidstructure.cpp +++ b/autotests/plasmoidstructure.cpp @@ -1,42 +1,29 @@ -/****************************************************************************** -* Copyright 2007-2009 by Aaron Seigo * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007-2009 Aaron Seigo + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "plasmoidstructure.h" #include #include #include "package.h" #include "config-package.h" namespace KPackage { void PlasmoidPackage::initPackage(Package *package) { GenericPackage::initPackage(package); package->setDefaultPackageRoot(QStringLiteral("plasma/plasmoids/")); package->addFileDefinition("mainscript", QStringLiteral("ui/main.qml"), i18n("Main Script File")); package->addFileDefinition("configmodel", QStringLiteral("config/config.qml"), i18n("Configuration UI pages model")); package->addFileDefinition("mainconfigxml", QStringLiteral("config/main.xml"), i18n("Configuration XML file")); } } // namespace KPackage diff --git a/autotests/plasmoidstructure.h b/autotests/plasmoidstructure.h index abf94af..ee202c0 100644 --- a/autotests/plasmoidstructure.h +++ b/autotests/plasmoidstructure.h @@ -1,38 +1,25 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef PLASMOIDSTRUCTURE_P_H #define PLASMOIDSTRUCTURE_P_H #include "kpackage/packagestructure.h" #include "../src/kpackage/private/packages_p.h" namespace KPackage { class PlasmoidPackage : public GenericPackage { Q_OBJECT public: void initPackage(Package *package) override; }; } // namespace KPackage #endif // PLASMOIDSTRUCTURE_P_H diff --git a/autotests/querytest.cpp b/autotests/querytest.cpp index 615463d..e493097 100644 --- a/autotests/querytest.cpp +++ b/autotests/querytest.cpp @@ -1,78 +1,65 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* Copyright 2014 by Marco Martin * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + SPDX-FileCopyrightText: 2014 Marco Martin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "querytest.h" #include #include #include #include "packagestructure.h" #include "packageloader.h" #include "config.h" void QueryTest::initTestCase() { QStandardPaths::setTestModeEnabled(true); //Remove any eventual installed package globally on the system qputenv("XDG_DATA_DIRS", "/not/valid"); qputenv("KPACKAGE_DEP_RESOLVERS_PATH", KPACKAGE_DEP_RESOLVERS); m_dataDir = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); m_dataDir.removeRecursively(); QVERIFY(m_dataDir.mkpath(QStringLiteral("."))); ps = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/Generic")); ps.addFileDefinition("mainscript", QStringLiteral("ui/main.qml"), i18n("Main Script File")); } void QueryTest::cleanupTestCase() { m_dataDir.removeRecursively(); } void QueryTest::installAndQuery() { // verify that no packages are installed QCOMPARE(KPackage::PackageLoader::self()->listPackages(QStringLiteral("KPackage/Generic")).count(), 0); // install some packages ps.install(QFINDTESTDATA("data/testpackage")); ps.install(QFINDTESTDATA("data/testfallbackpackage")); ps.install(QFINDTESTDATA("data/testjsonmetadatapackage")); QCOMPARE(KPackage::PackageLoader::self()->listPackages(QStringLiteral("KPackage/Generic")).count(), 3); // installing package with invalid metadata should not be possible ps.install(QFINDTESTDATA("data/testinvalidmetadata")); QCOMPARE(KPackage::PackageLoader::self()->listPackages(QStringLiteral("KPackage/Generic")).count(), 3); // package with valid dep information should be installed ps.install(QFINDTESTDATA("data/testpackagesdep")); QCOMPARE(KPackage::PackageLoader::self()->listPackages(QStringLiteral("KPackage/Generic")).count(), 4); // package with invalid dep information should not be installed ps.install(QFINDTESTDATA("data/testpackagesdepinvalid")); QCOMPARE(KPackage::PackageLoader::self()->listPackages(QStringLiteral("KPackage/Generic")).count(), 4); } QTEST_MAIN(QueryTest) diff --git a/autotests/querytest.h b/autotests/querytest.h index 5500f67..e48cf49 100644 --- a/autotests/querytest.h +++ b/autotests/querytest.h @@ -1,42 +1,29 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* Copyright 2014 by Marco Martin * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + SPDX-FileCopyrightText: 2014 Marco Martin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef PACKAGESTRUCTURETEST_H #include #include "kpackage/package.h" class QueryTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void installAndQuery(); private: KPackage::Package ps; QDir m_dataDir; }; #endif diff --git a/autotests/rccpackagetest.cpp b/autotests/rccpackagetest.cpp index a397c0e..cbe68c3 100644 --- a/autotests/rccpackagetest.cpp +++ b/autotests/rccpackagetest.cpp @@ -1,106 +1,93 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* Copyright 2014 Marco Martin * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + SPDX-FileCopyrightText: 2014 Marco Martin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "rccpackagetest.h" #include #include #include #include "packagestructure.h" #include "plasmoidstructure.h" #include "packageloader.h" void RccPackageTest::initTestCase() { QStandardPaths::setTestModeEnabled(true); QString destination = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/plasma/plasmoids/testpackage-rcc/"); QDir dir; dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/plasma/")); dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/plasma/plasmoids/")); dir.mkpath(destination); QVERIFY(dir.exists(destination)); //verify the source files exist QVERIFY(QFile::exists(QStringLiteral("../autotests/testpackage-rcc/metadata.json"))); QVERIFY(QFile::exists(QStringLiteral("../autotests/testpackage-rcc/contents.rcc"))); QFile::copy(QStringLiteral("../autotests/testpackage-rcc/metadata.json"), destination + QStringLiteral("metadata.json")); QFile::copy(QStringLiteral("../autotests/testpackage-rcc/contents.rcc"), destination + QStringLiteral("contents.rcc")); //verify they have been copied correctly QVERIFY(QFile::exists(destination + QStringLiteral("metadata.json"))); QVERIFY(QFile::exists(destination + QStringLiteral("contents.rcc"))); m_packagePath = "testpackage-rcc"; m_pkg = new KPackage::Package(new KPackage::PlasmoidPackage); m_pkg->setPath(m_packagePath); //Two package instances with the same resource m_pkg2 = new KPackage::Package(new KPackage::PlasmoidPackage); m_pkg2->setPath(m_packagePath); } void RccPackageTest::cleanupTestCase() { qDebug() << "cleaning up"; // Clean things up. QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).removeRecursively(); } void RccPackageTest::accessFiles() { QVERIFY(m_pkg->hasValidStructure()); QVERIFY(m_pkg->hasValidStructure()); //check for existence of all files QVERIFY(!m_pkg->filePath("ui", QStringLiteral("main.qml")).isEmpty()); QVERIFY(!m_pkg->filePath("ui", QStringLiteral("otherfile.qml")).isEmpty()); QVERIFY(!m_pkg->filePath("images", QStringLiteral("empty.png")).isEmpty()); QVERIFY(!m_pkg2->filePath("ui", QStringLiteral("main.qml")).isEmpty()); QVERIFY(!m_pkg2->filePath("ui", QStringLiteral("otherfile.qml")).isEmpty()); QVERIFY(!m_pkg2->filePath("images", QStringLiteral("empty.png")).isEmpty()); } void RccPackageTest::validate() { QCOMPARE(m_pkg->cryptographicHash(QCryptographicHash::Sha1), QByteArrayLiteral("ed0959c062b7ef7eaab5243e83e2f9afe5b3b15f")); QCOMPARE(m_pkg2->cryptographicHash(QCryptographicHash::Sha1), QByteArrayLiteral("ed0959c062b7ef7eaab5243e83e2f9afe5b3b15f")); } void RccPackageTest::testResourceRefCount() { delete m_pkg; m_pkg = nullptr; QVERIFY(m_pkg2->isValid()); QVERIFY(QFile::exists(QStringLiteral(":/plasma/plasmoids/testpackage-rcc/contents/ui/main.qml"))); //no reference from this package anymore delete m_pkg2; m_pkg2 = nullptr; QVERIFY(!QFile::exists(QStringLiteral(":/plasma/plasmoids/testpackage-rcc/contents/ui/main.qml"))); } QTEST_MAIN(RccPackageTest) diff --git a/autotests/rccpackagetest.h b/autotests/rccpackagetest.h index fc22b97..838026f 100644 --- a/autotests/rccpackagetest.h +++ b/autotests/rccpackagetest.h @@ -1,47 +1,34 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* Copyright 2014 Marco Martin * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + SPDX-FileCopyrightText: 2014 Marco Martin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef RCCPACKAGETEST_H #define RCCPACKAGETEST_H #include #include "kpackage/package.h" class RccPackageTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void accessFiles(); void validate(); void testResourceRefCount(); private: KPackage::Package *m_pkg; KPackage::Package *m_pkg2; QString m_packagePath; }; #endif diff --git a/src/kpackage/package.cpp b/src/kpackage/package.cpp index 2e805a1..183e680 100644 --- a/src/kpackage/package.cpp +++ b/src/kpackage/package.cpp @@ -1,1048 +1,1035 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* Copyright 2010 by Marco Martin * -* Copyright 2010 by Kevin Ottens * -* Copyright 2009 by Rob Scheepmaker * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + SPDX-FileCopyrightText: 2010 Marco Martin + SPDX-FileCopyrightText: 2010 Kevin Ottens + SPDX-FileCopyrightText: 2009 Rob Scheepmaker + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "package.h" #include #include #include #include "kpackage_debug.h" #include #include #include #include #include "config-package.h" #include #include #include "packagestructure.h" #include "packageloader.h" #include "private/package_p.h" //#include "private/packages_p.h" #include "private/packagejob_p.h" #include "private/packageloader_p.h" namespace KPackage { Package::Package(PackageStructure *structure) : d(new PackagePrivate()) { d->structure = structure; if (d->structure) { d->structure.data()->initPackage(this); auto desc = i18n("Desktop file that describes this package."); addFileDefinition("metadata", QStringLiteral("metadata.json"), desc); addFileDefinition("metadata", QStringLiteral("metadata.desktop"), desc); } } Package::Package(const Package &other) : d(other.d) { } Package::~Package() { //guard against deletion on application shutdown if (PackageDeletionNotifier::self()) { Q_EMIT PackageDeletionNotifier::self()->packageDeleted(this); } } Package &Package::operator=(const Package &rhs) { if (&rhs != this) { d = rhs.d; } return *this; } bool Package::hasValidStructure() const { return d->structure; } bool Package::isValid() const { if (!d->structure) { return false; } //Minimal packages with no metadata *are* supposed to be possible //so if !metadata().isValid() go ahead if (metadata().isValid() && metadata().value(QStringLiteral("isHidden"), QStringLiteral("false")) == QLatin1String("true")) { return false; } if (d->checkedValid) { return d->valid; } const QString rootPath = d->tempRoot.isEmpty() ? d->path : d->tempRoot; if(rootPath.isEmpty()) { return false; } d->valid = true; //search for the file in all prefixes and in all possible paths for each prefix //even if it's a big nested loop, usually there is one prefix and one location //so shouldn't cause too much disk access QHashIterator it(d->contents); while (it.hasNext()) { it.next(); if (!it.value().required) { continue; } const QString foundPath = filePath(it.key(), {}); if (foundPath.isEmpty()) { //qCWarning(KPACKAGE_LOG) << "Could not find required" << (it.value().directory ? "directory" : "file") << it.key() << "for package" << path() << "should be" << it.value().paths; d->valid = false; break; } } return d->valid; } QString Package::name(const QByteArray &key) const { QHash::const_iterator it = d->contents.constFind(key); if (it == d->contents.constEnd()) { return QString(); } return it.value().name; } bool Package::isRequired(const QByteArray &key) const { QHash::const_iterator it = d->contents.constFind(key); if (it == d->contents.constEnd()) { return false; } return it.value().required; } QStringList Package::mimeTypes(const QByteArray &key) const { QHash::const_iterator it = d->contents.constFind(key); if (it == d->contents.constEnd()) { return QStringList(); } if (it.value().mimeTypes.isEmpty()) { return d->mimeTypes; } return it.value().mimeTypes; } QString Package::defaultPackageRoot() const { return d->defaultPackageRoot; } void Package::setDefaultPackageRoot(const QString &packageRoot) { d.detach(); d->defaultPackageRoot = packageRoot; if (!d->defaultPackageRoot.isEmpty() && !d->defaultPackageRoot.endsWith(QLatin1Char('/'))) { d->defaultPackageRoot.append(QLatin1Char('/')); } } void Package::setFallbackPackage(const KPackage::Package &package) { if ((d->fallbackPackage && d->fallbackPackage->path() == package.path() && d->fallbackPackage->metadata() == package.metadata()) || //can't be fallback of itself (package.path() == path() && package.metadata() == metadata()) || d->hasCycle(package)) { return; } d->fallbackPackage = new Package(package); } KPackage::Package Package::fallbackPackage() const { if (d->fallbackPackage) { return (*d->fallbackPackage); } else { return Package(); } } bool Package::allowExternalPaths() const { return d->externalPaths; } void Package::setAllowExternalPaths(bool allow) { d.detach(); d->externalPaths = allow; } KPluginMetaData Package::metadata() const { //qCDebug(KPACKAGE_LOG) << "metadata: " << d->path << filePath("metadata"); if (!d->metadata && !d->path.isEmpty()) { const QString metadataPath = filePath("metadata"); if (!metadataPath.isEmpty()) { d->createPackageMetadata(metadataPath); } else { // d->path might still be a file, if its path has a trailing /, // the fileInfo lookup will fail, so remove it. QString p = d->path; if (p.endsWith(QLatin1Char('/'))) { p.chop(1); } QFileInfo fileInfo(p); if (fileInfo.isDir()) { d->createPackageMetadata(d->path); } else if (fileInfo.exists()) { d->path = fileInfo.canonicalFilePath(); d->tempRoot = d->unpack(p); } } } if (!d->metadata) { d->metadata = new KPluginMetaData(); } return *d->metadata; } QString PackagePrivate::unpack(const QString &filePath) { KArchive *archive = nullptr; QMimeDatabase db; QMimeType mimeType = db.mimeTypeForFile(filePath); if (mimeType.inherits(QStringLiteral("application/zip"))) { archive = new KZip(filePath); } else if (mimeType.inherits(QStringLiteral("application/x-compressed-tar")) || mimeType.inherits(QStringLiteral("application/x-gzip")) || mimeType.inherits(QStringLiteral("application/x-tar")) || mimeType.inherits(QStringLiteral("application/x-bzip-compressed-tar")) || mimeType.inherits(QStringLiteral("application/x-xz")) || mimeType.inherits(QStringLiteral("application/x-lzma"))) { archive = new KTar(filePath); } else { //qCWarning(KPACKAGE_LOG) << "Could not open package file, unsupported archive format:" << filePath << mimeType.name(); } QString tempRoot; if (archive && archive->open(QIODevice::ReadOnly)) { const KArchiveDirectory *source = archive->directory(); QTemporaryDir tempdir; tempdir.setAutoRemove(false); tempRoot = tempdir.path() + QLatin1Char('/'); source->copyTo(tempRoot); if (!QFile::exists(tempdir.path() + QLatin1String("/metadata.json")) && !QFile::exists(tempdir.path() + QLatin1String("/metadata.desktop"))) { // search metadata.desktop, the zip file might have the package contents in a subdirectory QDir unpackedPath(tempdir.path()); const auto entries = unpackedPath.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); for (const auto &pack : entries) { if (QFile::exists(pack.filePath() + QLatin1String("/metadata.json")) || QFile::exists(pack.filePath() + QLatin1String("/metadata.desktop"))) { tempRoot = pack.filePath() + QLatin1Char('/'); } } } createPackageMetadata(tempRoot); } else { //qCWarning(KPACKAGE_LOG) << "Could not open package file:" << path; } delete archive; return tempRoot; } bool PackagePrivate::isInsidePackageDir(const QString &canonicalPath) const { // make sure that the target file is actually inside the package dir to prevent // path traversal using symlinks or "../" path segments // make sure we got passed a valid path Q_ASSERT(QFileInfo::exists(canonicalPath)); Q_ASSERT(QFileInfo(canonicalPath).canonicalFilePath() == canonicalPath); // make sure that the base path is also canonical // this was not the case until 5.8, making this check fail e.g. if /home is a symlink // which in turn would make plasmashell not find the .qml files //installed package if (tempRoot.isEmpty()) { Q_ASSERT(QDir(path).exists()); Q_ASSERT(path == QStringLiteral("/") || QDir(path).canonicalPath() + QLatin1Char('/') == path); if (canonicalPath.startsWith(path)) { return true; } //temporary compressed package } else { Q_ASSERT(QDir(tempRoot).exists()); Q_ASSERT(tempRoot == QStringLiteral("/") || QDir(tempRoot).canonicalPath() + QLatin1Char('/') == tempRoot); if (canonicalPath.startsWith(tempRoot)) { return true; } } qCWarning(KPACKAGE_LOG) << "Path traversal attempt detected:" << canonicalPath << "is not inside" << path; return false; } QString Package::filePath(const QByteArray &fileType, const QString &filename) const { if (!d->valid) { QString result = d->fallbackFilePath(fileType, filename); if (result.isEmpty()) { // qCDebug(KPACKAGE_LOG) << fileType << "file with name" << filename // << "was not found in package with path" << d->path; } return result; } const QString discoveryKey(QString::fromUtf8(fileType) + filename); const auto path = d->discoveries.value(discoveryKey); if (!path.isEmpty()) { return path; } QStringList paths; if (!fileType.isEmpty()) { const auto contents = d->contents.constFind(fileType); if (contents == d->contents.constEnd()) { //qCDebug(KPACKAGE_LOG) << "package does not contain" << fileType << filename; return d->fallbackFilePath(fileType, filename); } paths = contents->paths; if (paths.isEmpty()) { //qCDebug(KPACKAGE_LOG) << "no matching path came of it, while looking for" << fileType << filename; d->discoveries.insert(discoveryKey, QString()); return d->fallbackFilePath(fileType, filename); } } else { //when filetype is empty paths is always empty, so try with an empty string paths << QString(); } //Nested loop, but in the medium case resolves to just one iteration // qCDebug(KPACKAGE_LOG) << "prefixes:" << d->contentsPrefixPaths.count() << d->contentsPrefixPaths; for (const QString &contentsPrefix : qAsConst(d->contentsPrefixPaths)) { QString prefix; //We are an installed package if (d->tempRoot.isEmpty()) { prefix = fileType == "metadata" ? d->path : (d->path + contentsPrefix); //We are a compressed package temporarily uncompressed in /tmp } else { prefix = fileType == "metadata" ? d->tempRoot : (d->tempRoot + contentsPrefix); } for (const QString &path : qAsConst(paths)) { QString file = prefix + path; if (!filename.isEmpty()) { file.append(QLatin1Char('/') + filename); } QFileInfo fi(file); if (fi.exists()) { if (d->externalPaths) { //qCDebug(KPACKAGE_LOG) << "found" << file; d->discoveries.insert(discoveryKey, file); return file; } // ensure that we don't return files outside of our base path // due to symlink or ../ games if (d->isInsidePackageDir(fi.canonicalFilePath())) { //qCDebug(KPACKAGE_LOG) << "found" << file; d->discoveries.insert(discoveryKey, file); return file; } } } } //qCDebug(KPACKAGE_LOG) << fileType << filename << "does not exist in" << prefixes << "at root" << d->path; return d->fallbackFilePath(fileType, filename); } QUrl Package::fileUrl(const QByteArray &fileType, const QString &filename) const { QString path = filePath(fileType, filename); //construct a qrc:/ url or a file:/ url, the only two protocols supported if (path.startsWith(QStringLiteral(":"))) { return QUrl(QStringLiteral("qrc") + path); } else { return QUrl::fromLocalFile(path); } } QStringList Package::entryList(const QByteArray &key) const { if (!d->valid) { return QStringList(); } QHash::const_iterator it = d->contents.constFind(key); if (it == d->contents.constEnd()) { //qCDebug(KPACKAGE_LOG) << "couldn't find" << key; return QStringList(); } //qCDebug(KPACKAGE_LOG) << "going to list" << key; QStringList list; for (const QString &prefix : qAsConst(d->contentsPrefixPaths)) { //qCDebug(KPACKAGE_LOG) << " looking in" << prefix; const QStringList paths = it.value().paths; for (const QString &path : paths) { //qCDebug(KPACKAGE_LOG) << " looking in" << path; if (it.value().directory) { //qCDebug(KPACKAGE_LOG) << "it's a directory, so trying out" << d->path + prefix + path; QDir dir(d->path + prefix + path); if (d->externalPaths) { list += dir.entryList(QDir::Files | QDir::Readable); } else { // ensure that we don't return files outside of our base path // due to symlink or ../ games QString canonicalized = dir.canonicalPath(); if (canonicalized.startsWith(d->path)) { list += dir.entryList(QDir::Files | QDir::Readable); } } } else { const QString fullPath = d->path + prefix + path; //qCDebug(KPACKAGE_LOG) << "it's a file at" << fullPath << QFile::exists(fullPath); if (!QFile::exists(fullPath)) { continue; } if (d->externalPaths) { list += fullPath; } else { QDir dir(fullPath); QString canonicalized = dir.canonicalPath() + QDir::separator(); //qCDebug(KPACKAGE_LOG) << "testing that" << canonicalized << "is in" << d->path; if (canonicalized.startsWith(d->path)) { list += fullPath; } } } } } return list; } void Package::setPath(const QString &path) { // if the path is already what we have, don't bother if (path == d->path) { return; } // our dptr is shared, and it is almost certainly going to change. // hold onto the old pointer just in case it does not, however! QExplicitlySharedDataPointer oldD(d); d.detach(); // without structure we're doomed if (!d->structure) { d->path.clear(); d->discoveries.clear(); d->valid = false; d->checkedValid = true; return; } // empty path => nothing to do if (path.isEmpty()) { d->path.clear(); d->discoveries.clear(); d->valid = false; d->structure.data()->pathChanged(this); return; } // now we look for all possible paths, including resolving // relative paths against the system search paths QStringList paths; if (QDir::isRelativePath(path)) { QString p; if (d->defaultPackageRoot.isEmpty()) { p = path % QLatin1Char('/'); } else { p = d->defaultPackageRoot % path % QLatin1Char('/'); } if (QDir::isRelativePath(p)) { //FIXME: can searching of the qrc be better? paths << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, p, QStandardPaths::LocateDirectory); } else { const QDir dir(p); if (QFile::exists(dir.canonicalPath())) { paths << p; } } //qCDebug(KPACKAGE_LOG) << "paths:" << p << paths << d->defaultPackageRoot; } else { const QDir dir(path); if (QFile::exists(dir.canonicalPath())) { paths << path; } } QFileInfo fileInfo(path); if (fileInfo.isFile() && d->tempRoot.isEmpty()) { d->path = fileInfo.canonicalFilePath(); d->tempRoot = d->unpack(path); } // now we search each path found, caching our previous path to know if // anything actually really changed const QString previousPath = d->path; for (const QString &p : qAsConst(paths)) { d->checkedValid = false; QDir dir(p); Q_ASSERT(QFile::exists(dir.canonicalPath())); //if it has a contents.rcc, give priority to it if (dir.exists(QStringLiteral("contents.rcc"))) { d->rccPath = dir.absoluteFilePath(QStringLiteral("contents.rcc")); QResource::registerResource(d->rccPath); //we need just the plugin name here, never the absolute path dir = QDir(QStringLiteral(":/") + defaultPackageRoot() + path.midRef(path.lastIndexOf(QLatin1Char('/')))); } d->path = dir.canonicalPath(); // canonicalPath() does not include a trailing slash (unless it is the root dir) if (!d->path.endsWith(QLatin1Char('/'))) { d->path.append(QLatin1Char('/')); } const QString fallbackPath = metadata().value(QStringLiteral("X-Plasma-RootPath")); if (!fallbackPath.isEmpty()) { const KPackage::Package fp = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"), fallbackPath); setFallbackPackage(fp); } // we need to tell the structure we're changing paths ... d->structure.data()->pathChanged(this); // ... and then testing the results for validity if (isValid()) { break; } } // if nothing did change, then we go back to the old dptr if (d->path == previousPath) { d = oldD; return; } // .. but something did change, so we get rid of our discovery cache d->discoveries.clear(); delete d->metadata; d->metadata = nullptr; // uh-oh, but we didn't end up with anything valid, so we sadly reset ourselves // to futility. if (!d->valid) { d->path.clear(); d->structure.data()->pathChanged(this); } } const QString Package::path() const { return d->path; } QStringList Package::contentsPrefixPaths() const { return d->contentsPrefixPaths; } void Package::setContentsPrefixPaths(const QStringList &prefixPaths) { d.detach(); d->contentsPrefixPaths = prefixPaths; if (d->contentsPrefixPaths.isEmpty()) { d->contentsPrefixPaths << QString(); } else { // the code assumes that the prefixes have a trailing slash // so let's make that true here QMutableStringListIterator it(d->contentsPrefixPaths); while (it.hasNext()) { it.next(); if (!it.value().endsWith(QLatin1Char('/'))) { it.setValue(it.value() % QLatin1Char('/')); } } } } #if KPACKAGE_BUILD_DEPRECATED_SINCE(5, 21) QString Package::contentsHash() const { return QString::fromLocal8Bit(cryptographicHash(QCryptographicHash::Sha1)); } #endif QByteArray Package::cryptographicHash(QCryptographicHash::Algorithm algorithm) const { if (!d->valid) { qCWarning(KPACKAGE_LOG) << "can not create hash due to Package being invalid"; return QByteArray(); } QCryptographicHash hash(algorithm); const QString metadataPath = QFile::exists(d->path + QLatin1String("metadata.json")) ? d->path + QLatin1String("metadata.json") : QFile::exists(d->path + QLatin1String("metadata.desktop")) ? d->path + QLatin1String("metadata.desktop") : QString(); if (!metadataPath.isEmpty()) { QFile f(metadataPath); if (f.open(QIODevice::ReadOnly)) { while (!f.atEnd()) { hash.addData(f.read(1024)); } } else { qCWarning(KPACKAGE_LOG) << "could not add" << f.fileName() << "to the hash; file could not be opened for reading."; } } else { qCWarning(KPACKAGE_LOG) << "no metadata at" << metadataPath; } for (const QString &prefix : qAsConst(d->contentsPrefixPaths)) { const QString basePath = d->path + prefix; QDir dir(basePath); if (!dir.exists()) { return QByteArray(); } d->updateHash(basePath, QString(), dir, hash); } return hash.result().toHex(); } void Package::addDirectoryDefinition(const QByteArray &key, const QString &path, const QString &name) { const auto contentsIt = d->contents.constFind(key); ContentStructure s; if (contentsIt != d->contents.constEnd()) { if (contentsIt->paths.contains(path) && contentsIt->directory == true && contentsIt->name == name) { return; } s = *contentsIt; } d.detach(); if (!name.isEmpty()) { s.name = name; } s.paths.append(path); s.directory = true; d->contents[key] = s; } void Package::addFileDefinition(const QByteArray &key, const QString &path, const QString &name) { const auto contentsIt = d->contents.constFind(key); ContentStructure s; if (contentsIt != d->contents.constEnd()) { if (contentsIt->paths.contains(path) && contentsIt->directory == true && contentsIt->name == name) { return; } s = *contentsIt; } d.detach(); if (!name.isEmpty()) { s.name = name; } s.paths.append(path); s.directory = false; d->contents[key] = s; } void Package::removeDefinition(const QByteArray &key) { if (d->contents.contains(key)) { d.detach(); d->contents.remove(key); } if (d->discoveries.contains(QString::fromLatin1(key))) { d.detach(); d->discoveries.remove(QString::fromLatin1(key)); } } void Package::setRequired(const QByteArray &key, bool required) { QHash::iterator it = d->contents.find(key); if (it == d->contents.end()) { return; } d.detach(); // have to find the item again after detaching: d->contents is a different object now it = d->contents.find(key); it.value().required = required; } void Package::setDefaultMimeTypes(const QStringList &mimeTypes) { d.detach(); d->mimeTypes = mimeTypes; } void Package::setMimeTypes(const QByteArray &key, const QStringList &mimeTypes) { QHash::iterator it = d->contents.find(key); if (it == d->contents.end()) { return; } d.detach(); // have to find the item again after detaching: d->contents is a different object now it = d->contents.find(key); it.value().mimeTypes = mimeTypes; } QList Package::directories() const { QList dirs; QHash::const_iterator it = d->contents.constBegin(); while (it != d->contents.constEnd()) { if (it.value().directory) { dirs << it.key(); } ++it; } return dirs; } QList Package::requiredDirectories() const { QList dirs; QHash::const_iterator it = d->contents.constBegin(); while (it != d->contents.constEnd()) { if (it.value().directory && it.value().required) { dirs << it.key(); } ++it; } return dirs; } QList Package::files() const { QList files; QHash::const_iterator it = d->contents.constBegin(); while (it != d->contents.constEnd()) { if (!it.value().directory) { files << it.key(); } ++it; } return files; } QList Package::requiredFiles() const { QList files; QHash::const_iterator it = d->contents.constBegin(); while (it != d->contents.constEnd()) { if (!it.value().directory && it.value().required) { files << it.key(); } ++it; } return files; } KJob *Package::install(const QString &sourcePackage, const QString &packageRoot) { const QString src = sourcePackage; QString dest = packageRoot.isEmpty() ? defaultPackageRoot() : packageRoot; KPackage::PackageLoader::self()->d->maxCacheAge = -1; //use absolute paths if passed, otherwise go under share if (!QDir::isAbsolutePath(dest)) { dest = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + dest; } if (!d->structure) { return nullptr; } //qCDebug(KPACKAGE_LOG) << "Source: " << src; //qCDebug(KPACKAGE_LOG) << "PackageRoot: " << dest; KJob *j = d->structure.data()->install(this, src, dest); return j; } KJob *Package::update(const QString &sourcePackage, const QString &packageRoot) { const QString src = sourcePackage; QString dest = packageRoot.isEmpty() ? defaultPackageRoot() : packageRoot; KPackage::PackageLoader::self()->d->maxCacheAge = -1; //use absolute paths if passed, otherwise go under share if (!QDir::isAbsolutePath(dest)) { dest = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + dest; } if (!d->structure) { return nullptr; } //qCDebug(KPACKAGE_LOG) << "Source: " << src; //qCDebug(KPACKAGE_LOG) << "PackageRoot: " << dest; KJob *j = d->structure.data()->update(this, src, dest); return j; } KJob *Package::uninstall(const QString &packageName, const QString &packageRoot) { KPackage::PackageLoader::self()->d->maxCacheAge = -1; d->createPackageMetadata(packageRoot + QLatin1Char('/') + packageName); if (!d->structure) { return nullptr; } return d->structure.data()->uninstall(this, packageRoot); } PackagePrivate::PackagePrivate() : QSharedData(), fallbackPackage(nullptr), metadata(nullptr), externalPaths(false), valid(false), checkedValid(false) { contentsPrefixPaths << QStringLiteral("contents/"); } PackagePrivate::PackagePrivate(const PackagePrivate &other) : QSharedData() { *this = other; metadata = nullptr; } PackagePrivate::~PackagePrivate() { if (!rccPath.isEmpty()) { //qresource register/unregisterpath is refcounted if we call it two times //on the same path, the resource will actually be unregistered only when //unregister is called 2 times QResource::unregisterResource(rccPath); } if (!tempRoot.isEmpty()) { QDir dir(tempRoot); dir.removeRecursively(); } delete metadata; delete fallbackPackage; } PackagePrivate &PackagePrivate::operator=(const PackagePrivate &rhs) { if (&rhs == this) { return *this; } structure = rhs.structure; if (rhs.fallbackPackage) { fallbackPackage = new Package(*rhs.fallbackPackage); } else { fallbackPackage = nullptr; } path = rhs.path; contentsPrefixPaths = rhs.contentsPrefixPaths; contents = rhs.contents; mimeTypes = rhs.mimeTypes; defaultPackageRoot = rhs.defaultPackageRoot; metadata = nullptr; externalPaths = rhs.externalPaths; valid = rhs.valid; return *this; } void PackagePrivate::updateHash(const QString &basePath, const QString &subPath, const QDir &dir, QCryptographicHash &hash) { // hash is calculated as a function of: // * files ordered alphabetically by name, with each file's: // * path relative to the content root // * file data // * directories ordered alphabetically by name, with each dir's: // * path relative to the content root // * file listing (recursing) // symlinks (in both the file and dir case) are handled by adding // the name of the symlink itself and the abs path of what it points to const QDir::SortFlags sorting = QDir::Name | QDir::IgnoreCase; const QDir::Filters filters = QDir::Hidden | QDir::System | QDir::NoDotAndDotDot; const auto lstEntries = dir.entryList(QDir::Files | filters, sorting); for (const QString &file : lstEntries) { if (!subPath.isEmpty()) { hash.addData(subPath.toUtf8()); } hash.addData(file.toUtf8()); QFileInfo info(dir.path() + QLatin1Char('/') + file); if (info.isSymLink()) { hash.addData(info.symLinkTarget().toUtf8()); } else { QFile f(info.filePath()); if (f.open(QIODevice::ReadOnly)) { while (!f.atEnd()) { hash.addData(f.read(1024)); } } else { qCWarning(KPACKAGE_LOG) << "could not add" << f.fileName() << "to the hash; file could not be opened for reading. " << "permissions fail?" << info.permissions() << info.isFile(); } } } const auto lstEntries2 = dir.entryList(QDir::Dirs | filters, sorting); for (const QString &subDirPath : lstEntries2) { const QString relativePath = subPath + subDirPath + QLatin1Char('/'); hash.addData(relativePath.toUtf8()); QDir subDir(dir.path()); subDir.cd(subDirPath); if (subDir.path() != subDir.canonicalPath()) { hash.addData(subDir.canonicalPath().toUtf8()); } else { updateHash(basePath, relativePath, subDir, hash); } } } void PackagePrivate::createPackageMetadata(const QString &path) { const bool isDir = QFileInfo(path).isDir(); delete metadata; if (isDir && QFile::exists(path + QStringLiteral("/metadata.json"))) { metadata = new KPluginMetaData(path + QStringLiteral("/metadata.json")); } else if (isDir && QFile::exists(path + QStringLiteral("/metadata.desktop"))) { auto md = KPluginMetaData::fromDesktopFile(path + QStringLiteral("/metadata.desktop"), {QStringLiteral(":/kservicetypes5/kpackage-generic.desktop")}); metadata = new KPluginMetaData(md); } else { if (isDir) { qCWarning(KPACKAGE_LOG) << "No metadata file in the package, expected it at:" << path; } else if (path.endsWith(QLatin1String(".desktop"))) { auto md = KPluginMetaData::fromDesktopFile(path, {QStringLiteral(":/kservicetypes5/kpackage-generic.desktop")}); metadata = new KPluginMetaData(md); } else { metadata = new KPluginMetaData(path); } } } QString PackagePrivate::fallbackFilePath(const QByteArray &key, const QString &filename) const { //don't fallback if the package isn't valid and never fallback the metadata file if (qstrcmp(key, "metadata") != 0 && fallbackPackage && fallbackPackage->isValid()) { return fallbackPackage->filePath(key, filename); } else { return QString(); } } bool PackagePrivate::hasCycle(const KPackage::Package &package) { if (!package.d->fallbackPackage) { return false; } //This is the Floyd cycle detection algorithm //http://en.wikipedia.org/wiki/Cycle_detection#Tortoise_and_hare KPackage::Package *slowPackage = const_cast(&package); KPackage::Package *fastPackage = const_cast(&package); while (fastPackage && fastPackage->d->fallbackPackage) { //consider two packages the same if they have the same metadata if ((fastPackage->d->fallbackPackage->metadata().isValid() && fastPackage->d->fallbackPackage->metadata() == slowPackage->metadata()) || (fastPackage->d->fallbackPackage->d->fallbackPackage && fastPackage->d->fallbackPackage->d->fallbackPackage->metadata().isValid() && fastPackage->d->fallbackPackage->d->fallbackPackage->metadata() == slowPackage->metadata())) { qCWarning(KPACKAGE_LOG) << "Warning: the fallback chain of " << package.metadata().pluginId() << "contains a cyclical dependency."; return true; } fastPackage = fastPackage->d->fallbackPackage->d->fallbackPackage; slowPackage = slowPackage->d->fallbackPackage; } return false; } Q_GLOBAL_STATIC(PackageDeletionNotifier, s_packageDeletionNotifier) PackageDeletionNotifier* PackageDeletionNotifier::self() { return s_packageDeletionNotifier; } } // Namespace #include "private/moc_package_p.cpp" diff --git a/src/kpackage/package.h b/src/kpackage/package.h index 08c0b00..64e670c 100644 --- a/src/kpackage/package.h +++ b/src/kpackage/package.h @@ -1,407 +1,394 @@ -/****************************************************************************** -* Copyright 2007-2011 by Aaron Seigo * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007-2011 Aaron Seigo + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef KPACKAGE_PACKAGE_H #define KPACKAGE_PACKAGE_H #include #include #include #include #include #include #include namespace KPackage { /** * @class Package kpackage/package.h * * @short object representing an installed package * * Package defines what is in a package and provides easy access to the contents. * * To define a package, one might write the following code: * @code Package package; package.addDirectoryDefinition("images", "pics/", i18n("Images")); QStringList mimeTypes; mimeTypes << "image/svg" << "image/png" << "image/jpeg"; package.setMimeTypes("images", mimeTypes); package.addDirectoryDefinition("scripts", "code/", i18n("Executable Scripts")); mimeTypes.clear(); mimeTypes << "text/\*"; package.setMimeTypes("scripts", mimeTypes); package.addFileDefinition("mainscript", "code/main.js", i18n("Main Script File")); package.setRequired("mainscript", true); @endcode * One may also choose to create a subclass of PackageStructure and include the setup * in the constructor. * * Either way, Package creates a self-documenting contract between the packager and * the application without exposing package internals such as actual on-disk structure * of the package or requiring that all contents be explicitly known ahead of time. * * Subclassing PackageStructure does have provide a number of potential const benefits: * * the package can be notified of path changes via the virtual pathChanged() method * * the subclass may implement mechanisms to install and remove packages using the * virtual install and uninstall methods * * subclasses can be compiled as plugins for easy re-use **/ //TODO: write documentation on USING a package class PackagePrivate; class PackageStructure; class KPACKAGE_EXPORT Package { public: /** * Error codes for the install/update/remove jobs * @since 5.17 */ enum JobError { RootCreationError = KJob::UserDefinedError + 1, /**< Cannot create package root directory */ PackageFileNotFoundError, /**< The package file does not exist */ UnsupportedArchiveFormatError, /**< The archive format of the package is not supported */ PackageOpenError, /**< Can't open the package file for reading */ MetadataFileMissingError, /**< The package doesn't have a metadata.desktop file */ PluginNameMissingError, /**< The metadata.desktop file doesn't specify a plugin name */ PluginNameInvalidError, /**< The plugin name contains characters different from letters, digits, dots and underscores */ UpdatePackageTypeMismatchError, /**< A package with this plugin name was already installed, but has a different type in the metadata.desktop file */ OldVersionRemovalError, /**< Failed to remove the old version of the package during an upgrade */ NewerVersionAlreadyInstalledError, /**< We tried to update, but the same version or a newer one is already installed */ PackageAlreadyInstalledError, /**< The package is already installed and a normal install (not update) was performed */ PackageMoveError, /**< Failure to move a package from the system temporary folder to its final destination */ PackageCopyError, /**< Failure to copy a package folder from somewhere in the filesystem to its final destination */ PackageUninstallError /**< Failure to uninstall a package */ }; /** * Default constructor * * @param structure if a null pointer is passed in, this will creates an empty (invalid) Package; * otherwise the structure is allowed to set up the Package's initial layout * @since 4.6 */ explicit Package(PackageStructure *structure = nullptr); /** * Copy constructor * @since 4.6 */ Package(const Package &other); virtual ~Package(); /** * Assignment operator * @since 4.6 */ Package &operator=(const Package &rhs); /** * @return true if this package has a valid PackageStructure associatedw it with it. * A package may not be valid, but have a valid structure. Useful when dealing with * Package objects in a semi-initialized state (e.g. before calling setPath()) * @since 5.1 */ bool hasValidStructure() const; /** * @return true if all the required components exist **/ bool isValid() const; /** * Sets the path to the root of this package * @param path an absolute path, or a relative path to the default package root * @since 4.3 */ void setPath(const QString &path); /** * @return the path to the root of this particular package */ const QString path() const; /** * Get the path to a given file based on the key and an optional filename. * Example: finding the main script in a scripting package: * filePath("mainscript") * * Example: finding a specific image in the images directory: * filePath("images", "myimage.png") * * @param key the key of the file type to look for, * @param filename optional name of the file to locate within the package * @return path to the file on disk. QString() if not found. **/ QString filePath(const QByteArray &key, const QString &filename = QString()) const; /** * Get the url to a given file based on the key and an optional filename, is the file:// or qrc:// format * Example: finding the main script in a scripting package: * filePath("mainscript") * * Example: finding a specific image in the images directory: * filePath("images", "myimage.png") * * @param key the key of the file type to look for, * @param filename optional name of the file to locate within the package * @return path to the file on disk. QString() if not found. * @since 5.41 **/ QUrl fileUrl(const QByteArray &key, const QString &filename = QString()) const; /** * Get the list of files of a given type. * * @param fileType the type of file to look for, as defined in the * package structure. * @return list of files by name, suitable for passing to filePath **/ QStringList entryList(const QByteArray &key) const; /** * @return user visible name for the given entry **/ QString name(const QByteArray &key) const; /** * @return true if the item at path exists and is required **/ bool isRequired(const QByteArray &key) const; /** * @return the mimeTypes associated with the path, if any **/ QStringList mimeTypes(const QByteArray &key) const; /** * @return the prefix paths inserted between the base path and content entries, in order of priority. * When searching for a file, all paths will be tried in order. * @since 4.6 */ QStringList contentsPrefixPaths() const; /** * @return preferred package root. This defaults to kpackage/generic/ */ QString defaultPackageRoot() const; /** * @return true if paths/symlinks outside the package itself should be followed. * By default this is set to false for security reasons. */ bool allowExternalPaths() const; /** * @return the package metadata object. */ KPluginMetaData metadata() const; #if KPACKAGE_ENABLE_DEPRECATED_SINCE(5, 21) /** * @return a SHA1 hash digest of the contents of the package in hexadecimal form * @since 4.4 * @deprecated Since 5.21 use cryptographicHash */ KPACKAGE_DEPRECATED_VERSION(5, 21, "Use Package::cryptographicHash(QCryptographicHash::Algorithm)") QString contentsHash() const; #endif /** * @return a hash digest of the contents of the package in hexadecimal form * @since 5.21 */ QByteArray cryptographicHash(QCryptographicHash::Algorithm algorithm) const; /** * Adds a directory to the structure of the package. It is added as * a not-required element with no associated mimeTypes. * * Starting in 4.6, if an entry with the given key * already exists, the path is added to it as a search alternative. * * @param key used as an internal label for this directory * @param path the path within the package for this directory * @param name the user visible (translated) name for the directory **/ void addDirectoryDefinition(const QByteArray &key, const QString &path, const QString &name); /** * Adds a file to the structure of the package. It is added as * a not-required element with no associated mimeTypes. * * Starting in 4.6, if an entry with the given key * already exists, the path is added to it as a search alternative. * * @param key used as an internal label for this file * @param path the path within the package for this file * @param name the user visible (translated) name for the file **/ void addFileDefinition(const QByteArray &key, const QString &path, const QString &name); /** * Removes a definition from the structure of the package. * @since 4.6 * @param key the internal label of the file or directory to remove */ void removeDefinition(const QByteArray &key); /** * Sets whether or not a given part of the structure is required or not. * The path must already have been added using addDirectoryDefinition * or addFileDefinition. * * @param key the entry within the package * @param required true if this entry is required, false if not */ void setRequired(const QByteArray &key, bool required); /** * Defines the default mimeTypes for any definitions that do not have * associated mimeTypes. Handy for packages with only one or predominantly * one file type. * * @param mimeTypes a list of mimeTypes **/ void setDefaultMimeTypes(const QStringList &mimeTypes); /** * Define mimeTypes for a given part of the structure * The path must already have been added using addDirectoryDefinition * or addFileDefinition. * * @param key the entry within the package * @param mimeTypes a list of mimeTypes **/ void setMimeTypes(const QByteArray &key, const QStringList &mimeTypes); /** * Sets the prefixes that all the contents in this package should * appear under. This defaults to "contents/" and is added automatically * between the base path and the entries as defined by the package * structure. Multiple entries can be added. * In this case each file request will be searched in all prefixes in order, * and the first found will be returned. * * @param prefix paths the directory prefix to use * @since 4.6 */ void setContentsPrefixPaths(const QStringList &prefixPaths); /** * Sets whether or not external paths/symlinks can be followed by a package * @param allow true if paths/symlinks outside of the package should be followed, * false if they should be rejected. */ void setAllowExternalPaths(bool allow); /** * Sets preferred package root. */ void setDefaultPackageRoot(const QString &packageRoot); /** * Sets the fallback package root path * If a file won't be found in this package, it will search it in the package * with the same structure identified by path * It is intended to be used by the packageStructure * @param path package root path @see setPath */ void setFallbackPackage(const KPackage::Package &package); /** * @return The fallback package root path */ KPackage::Package fallbackPackage() const; // Content structure description methods /** * @return all directories registered as part of this Package's structure */ QList directories() const; /** * @return all directories registered as part of this Package's required structure */ QList requiredDirectories() const; /** * @return all files registered as part of this Package's structure */ QList files() const; /** * @return all files registered as part of this Package's required structure */ QList requiredFiles() const; /** * Installs a package matching this package structure. By default installs a * native KPackage::Package. * After the KJob will emitted finished(), if the install went well * the Package instance will be guaranteed to have loaded the package just * installed, and be valid and usable. * * @return KJob to track installation progress and result **/ KJob *install(const QString &sourcePackage, const QString &packageRoot = QString()); /** * Updates a package matching this package structure. By default installs a * native KPackage::Package. If an older version is already installed, * it removes the old one. If the installed one is newer, * an error will occur. * After the KJob will emitted finished(), if the install went well * the Package instance will be guaranteed to have loaded the package just * updated, and be valid and usable. * * @return KJob to track installation progress and result * @since 5.17 **/ KJob *update(const QString &sourcePackage, const QString &packageRoot = QString()); /** * Uninstalls a package matching this package structure. * * @return KJob to track removal progress and result */ KJob *uninstall(const QString &packageName, const QString &packageRoot); private: QExplicitlySharedDataPointer d; friend class PackagePrivate; }; } Q_DECLARE_METATYPE(KPackage::Package) #endif diff --git a/src/kpackage/packageloader.cpp b/src/kpackage/packageloader.cpp index 43a2939..da1b1ec 100644 --- a/src/kpackage/packageloader.cpp +++ b/src/kpackage/packageloader.cpp @@ -1,398 +1,385 @@ /* - * Copyright 2010 Ryan Rix - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ + SPDX-FileCopyrightText: 2010 Ryan Rix + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "packageloader.h" #include "private/packageloader_p.h" #include #include #include #include #include #include #include "kpackage_debug.h" #include #include #include #include #include "config-package.h" #include "private/packages_p.h" #include "package.h" #include "packagestructure.h" #include "private/packagejobthread_p.h" namespace KPackage { static PackageLoader *s_packageTrader = nullptr; QSet PackageLoaderPrivate::s_customCategories; QSet PackageLoaderPrivate::knownCategories() { // this is to trick the translation tools into making the correct // strings for translation QSet categories = s_customCategories; categories << QStringLiteral(I18N_NOOP("Accessibility")).toLower() << QStringLiteral(I18N_NOOP("Application Launchers")).toLower() << QStringLiteral(I18N_NOOP("Astronomy")).toLower() << QStringLiteral(I18N_NOOP("Date and Time")).toLower() << QStringLiteral(I18N_NOOP("Development Tools")).toLower() << QStringLiteral(I18N_NOOP("Education")).toLower() << QStringLiteral(I18N_NOOP("Environment and Weather")).toLower() << QStringLiteral(I18N_NOOP("Examples")).toLower() << QStringLiteral(I18N_NOOP("File System")).toLower() << QStringLiteral(I18N_NOOP("Fun and Games")).toLower() << QStringLiteral(I18N_NOOP("Graphics")).toLower() << QStringLiteral(I18N_NOOP("Language")).toLower() << QStringLiteral(I18N_NOOP("Mapping")).toLower() << QStringLiteral(I18N_NOOP("Miscellaneous")).toLower() << QStringLiteral(I18N_NOOP("Multimedia")).toLower() << QStringLiteral(I18N_NOOP("Online Services")).toLower() << QStringLiteral(I18N_NOOP("Productivity")).toLower() << QStringLiteral(I18N_NOOP("System Information")).toLower() << QStringLiteral(I18N_NOOP("Utilities")).toLower() << QStringLiteral(I18N_NOOP("Windows and Tasks")).toLower(); return categories; } QString PackageLoaderPrivate::parentAppConstraint(const QString &parentApp) { if (parentApp.isEmpty()) { const QCoreApplication *app = QCoreApplication::instance(); if (!app) { return QString(); } return QStringLiteral("((not exist [X-KDE-ParentApp] or [X-KDE-ParentApp] == '') or [X-KDE-ParentApp] == '%1')") .arg(app->applicationName()); } return QStringLiteral("[X-KDE-ParentApp] == '%1'").arg(parentApp); } PackageLoader::PackageLoader() : d(new PackageLoaderPrivate) { } PackageLoader::~PackageLoader() { for (auto wp : qAsConst(d->structures)) { delete wp.data(); } delete d; } void PackageLoader::setPackageLoader(PackageLoader *loader) { if (!s_packageTrader) { s_packageTrader = loader; } else { #ifndef NDEBUG // qCDebug(KPACKAGE_LOG) << "Cannot set packageTrader, already set!" << s_packageTrader; #endif } } PackageLoader *PackageLoader::self() { if (!s_packageTrader) { // we have been called before any PackageLoader was set, so just use the default // implementation. this prevents plugins from nefariously injecting their own // plugin loader if the app doesn't s_packageTrader = new PackageLoader; s_packageTrader->d->isDefaultLoader = true; } return s_packageTrader; } Package PackageLoader::loadPackage(const QString &packageFormat, const QString &packagePath) { if (!d->isDefaultLoader) { Package p = internalLoadPackage(packageFormat); if (p.hasValidStructure()) { if (!packagePath.isEmpty()) { p.setPath(packagePath); } return p; } } if (packageFormat.isEmpty()) { return Package(); } PackageStructure *structure = loadPackageStructure(packageFormat); if (structure) { Package p(structure); if (!packagePath.isEmpty()) { p.setPath(packagePath); } return p; } #ifndef NDEBUG // qCDebug(KPACKAGE_LOG) << "Couldn't load Package for" << packageFormat << "! reason given: " << error; #endif return Package(); } QList PackageLoader::listPackages(const QString &packageFormat, const QString &packageRoot) { // Note: Use QDateTime::currentSecsSinceEpoch() once we can depend on Qt 5.8 const qint64 now = qRound64(QDateTime::currentMSecsSinceEpoch() / 1000.0); bool useRuntimeCache = true; if (now - d->pluginCacheAge > d->maxCacheAge && d->pluginCacheAge != 0) { // cache is old and we're not within a few seconds of startup anymore useRuntimeCache = false; d->pluginCache.clear(); } const QString cacheKey = QStringLiteral("%1.%2").arg(packageFormat, packageRoot); if (useRuntimeCache) { auto it = d->pluginCache.constFind(cacheKey); if (it != d->pluginCache.constEnd()) { return *it; } } if (d->pluginCacheAge == 0) { d->pluginCacheAge = now; } QList lst; //has been a root specified? QString actualRoot = packageRoot; //try to take it from the package structure if (actualRoot.isEmpty()) { PackageStructure *structure = d->structures.value(packageFormat).data(); if (!structure) { if (packageFormat == QStringLiteral("KPackage/Generic")) { structure = new GenericPackage(); } else if (packageFormat == QStringLiteral("KPackage/GenericQML")) { structure = new GenericQMLPackage(); } } if (!structure) { structure = loadPackageStructure(packageFormat); } if (structure) { d->structures.insert(packageFormat, structure); Package p(structure); actualRoot = p.defaultPackageRoot(); } } if (actualRoot.isEmpty()) { actualRoot = packageFormat; } QSet uniqueIds; QStringList paths; if (QDir::isAbsolutePath(actualRoot)) { paths = QStringList(actualRoot); } else { const auto listPath = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); for (const QString &path : listPath) { paths += path + QLatin1Char('/') + actualRoot; } } for (auto const &plugindir : qAsConst(paths)) { const QString &_ixfile = plugindir + s_kpluginindex; if (QFile::exists(_ixfile)) { KCompressionDevice indexFile(_ixfile, KCompressionDevice::BZip2); qCDebug(KPACKAGE_LOG) << "kpluginindex: Using indexfile: " << _ixfile; indexFile.open(QIODevice::ReadOnly); QJsonDocument jdoc = QJsonDocument::fromBinaryData(indexFile.readAll()); indexFile.close(); QJsonArray plugins = jdoc.array(); for (QJsonArray::const_iterator iter = plugins.constBegin(); iter != plugins.constEnd(); ++iter) { const QJsonObject &obj = QJsonValue(*iter).toObject(); const QString &pluginFileName = obj.value(QStringLiteral("FileName")).toString(); const KPluginMetaData m(obj, QString(), pluginFileName); if (m.isValid() && !uniqueIds.contains(m.pluginId())) { uniqueIds << m.pluginId(); lst << m; } } } else { qCDebug(KPACKAGE_LOG) << "kpluginindex: Not cached" << plugindir; // If there's no cache file, fall back to listing the directory const QDirIterator::IteratorFlags flags = QDirIterator::Subdirectories; const QStringList nameFilters = { QStringLiteral("metadata.json"), QStringLiteral("metadata.desktop") }; QDirIterator it(plugindir, nameFilters, QDir::Files, flags); QSet dirs; while (it.hasNext()) { it.next(); const QString dir = it.fileInfo().absoluteDir().path(); if (dirs.contains(dir)) { continue; } dirs << dir; const QString metadataPath = it.fileInfo().absoluteFilePath(); const KPluginMetaData info(metadataPath); if (!info.isValid() || uniqueIds.contains(info.pluginId())) { continue; } if (packageFormat.isEmpty() || info.serviceTypes().isEmpty() || info.serviceTypes().contains(packageFormat)) { uniqueIds << info.pluginId(); lst << info; } } } } if (useRuntimeCache) { d->pluginCache.insert(cacheKey, lst); } return lst; } QList PackageLoader::findPackages(const QString &packageFormat, const QString &packageRoot, std::function filter) { QList lst; const auto lstPlugins = listPackages(packageFormat, packageRoot); for (auto const &plugin : lstPlugins) { if (!filter || filter(plugin)) { lst << plugin; } } return lst; } KPackage::PackageStructure *PackageLoader::loadPackageStructure(const QString &packageFormat) { PackageStructure *structure = d->structures.value(packageFormat).data(); if (!structure) { if (packageFormat == QStringLiteral("KPackage/Generic")) { structure = new GenericPackage(); d->structures.insert(packageFormat, structure); } else if (packageFormat == QStringLiteral("KPackage/GenericQML")) { structure = new GenericQMLPackage(); d->structures.insert(packageFormat, structure); } } if (structure) { return structure; } QStringList libraryPaths; const QString subDirectory = QStringLiteral("kpackage/packagestructure"); const auto lstPaths = QCoreApplication::libraryPaths(); for (const QString &dir : lstPaths) { QString d = dir + QDir::separator() + subDirectory; if (!d.endsWith(QDir::separator())) { d += QDir::separator(); } libraryPaths << d; } QString pluginFileName; for (const QString &plugindir : qAsConst(libraryPaths)) { const QString &_ixfile = plugindir + s_kpluginindex; KCompressionDevice indexFile(_ixfile, KCompressionDevice::BZip2); if (QFile::exists(_ixfile)) { indexFile.open(QIODevice::ReadOnly); QJsonDocument jdoc = QJsonDocument::fromBinaryData(indexFile.readAll()); indexFile.close(); QJsonArray plugins = jdoc.array(); for (QJsonArray::const_iterator iter = plugins.constBegin(); iter != plugins.constEnd(); ++iter) { const QJsonObject &obj = QJsonValue(*iter).toObject(); const QString &candidate = obj.value(QStringLiteral("FileName")).toString(); const KPluginMetaData m(obj, candidate); if (m.isValid() && m.pluginId() == packageFormat) { pluginFileName = candidate; break; } } } else { QVector plugins = KPluginLoader::findPlugins(plugindir); QVectorIterator iter(plugins); while (iter.hasNext()) { auto md = iter.next(); if (md.isValid() && md.pluginId() == packageFormat) { pluginFileName = md.fileName(); break; } } } } QString error; if (!pluginFileName.isEmpty()) { KPluginLoader loader(pluginFileName); const QVariantList argsWithMetaData = QVariantList() << loader.metaData().toVariantMap(); KPluginFactory *factory = loader.factory(); if (factory) { structure = factory->create(nullptr, argsWithMetaData); if (!structure) { error = QCoreApplication::translate("", "No service matching the requirements was found"); } } } if (structure && !error.isEmpty()) { qCWarning(KPACKAGE_LOG) << i18n("Could not load installer for package of type %1. Error reported was: %2", packageFormat, error); } if (structure) { d->structures.insert(packageFormat, structure); } return structure; } void PackageLoader::addKnownPackageStructure(const QString &packageFormat, KPackage::PackageStructure *structure) { d->structures.insert(packageFormat, structure); } Package PackageLoader::internalLoadPackage(const QString &name) { Q_UNUSED(name); return Package(); } } // KPackage Namespace diff --git a/src/kpackage/packageloader.h b/src/kpackage/packageloader.h index 3bb5188..355a78a 100644 --- a/src/kpackage/packageloader.h +++ b/src/kpackage/packageloader.h @@ -1,143 +1,130 @@ /* - * Copyright 2010 by Ryan Rix - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ + SPDX-FileCopyrightText: 2010 Ryan Rix + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef KPACKAGE_LOADER_H #define KPACKAGE_LOADER_H #include #include namespace KPackage { class PackageLoaderPrivate; /** * @class PackageLoader kpackage/packageloader.h * * This is an abstract base class which defines an interface to which the package * loading logic can communicate with a parent application. The plugin loader * must be set before any plugins are loaded, otherwise (for safety reasons), the * default PackageLoader implementation will be used. The reimplemented version should * not do more than simply returning a loaded plugin. It should not init() it, and it should not * hang on to it. * * @author Ryan Rix **/ class KPACKAGE_EXPORT PackageLoader { public: /** * Load a Package plugin. * * @param packageFormat the format of the package to load * @param packagePath the package name: the path of the package relative to the * packageFormat root path. If not specified it will have to be set manually * with Package::setPath() by the caller. * * @return a Package object matching name, or an invalid package on failure **/ Package loadPackage(const QString &packageFormat, const QString &packagePath = QString()); /** * List all available packages of a certain type * * @param packageFormat the format of the packages to list * @param packageRoot the root folder where the packages are installed. * If not specified the default from the packageformat will be taken. * * @return metadata for all the matching packages */ QList listPackages(const QString &packageFormat, const QString &packageRoot = QString()); /** * List package of a certain type that match a certain filter function * * @param packageFormat the format of the packages to list * @param packageRoot the root folder where the packages are installed. * If not specified the default from the packageformat will be taken. * @param filter a filter function that will be called on each package: * will return true for the matching ones * * @return metadata for all the matching packages * @since 5.10 */ QList findPackages(const QString &packageFormat, const QString &packageRoot = QString(), std::function filter = std::function()); /** * Loads a PackageStructure for a given format. The structure can then be used as * paramenter for a Package instance constructor * @param packageFormat the package format, such as "KPackage/GenericQML" * @return the structure instance */ KPackage::PackageStructure *loadPackageStructure(const QString &packageFormat); /** * Adds a new known package structure that can be used by the functions to load packages such * as loadPackage, findPackages etc * @param packageFormat the package format, such as "KPackage/GenericQML" * @param structure the package structure we want to be able to load packages from * @since 5.10 */ void addKnownPackageStructure(const QString &packageFormat, KPackage::PackageStructure *structure); /** * Set the plugin loader which will be queried for all loads. * * @param loader A subclass of PackageLoader which will be supplied * by the application **/ static void setPackageLoader(PackageLoader *loader); /** * Return the active plugin loader **/ static PackageLoader *self(); protected: /** * A re-implementable method that allows subclasses to override * the default behaviour of loadPackage. If the service requested is not recognized, * then the implementation should return an empty and invalid Package(). * This method is called * by loadPackage prior to attempting to load a Package using the standard * plugin mechanisms. * * @param packageFormat the format of the package to load * * @return a Package instance with the proper PackageStructure **/ virtual Package internalLoadPackage(const QString &packageFormat); PackageLoader(); virtual ~PackageLoader(); private: friend class Package; PackageLoaderPrivate *const d; Q_DISABLE_COPY(PackageLoader) }; } Q_DECLARE_METATYPE(KPackage::PackageLoader *) #endif diff --git a/src/kpackage/packagestructure.cpp b/src/kpackage/packagestructure.cpp index a04d244..ce27338 100644 --- a/src/kpackage/packagestructure.cpp +++ b/src/kpackage/packagestructure.cpp @@ -1,72 +1,59 @@ -/****************************************************************************** -* Copyright 2011 by Aaron Seigo * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2011 Aaron Seigo + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "packagestructure.h" #include "kpackage_debug.h" #include #include "private/package_p.h" namespace KPackage { PackageStructure::PackageStructure(QObject *parent, const QVariantList &args) : QObject(parent), d(nullptr) { Q_UNUSED(args) } PackageStructure::~PackageStructure() { } void PackageStructure::initPackage(Package *package) { Q_UNUSED(package) } void PackageStructure::pathChanged(Package *package) { Q_UNUSED(package) } KJob *PackageStructure::install(Package *package, const QString &archivePath, const QString &packageRoot) { PackageJob *j = new PackageJob(package); j->install(archivePath, packageRoot); return j; } KJob *PackageStructure::update(Package *package, const QString &archivePath, const QString &packageRoot) { PackageJob *j = new PackageJob(package); j->update(archivePath, packageRoot); return j; } KJob *PackageStructure::uninstall(Package *package, const QString &packageRoot) { PackageJob *j = new PackageJob(package); j->uninstall(packageRoot + QLatin1Char('/') + package->metadata().pluginId()); return j; } } #include "moc_packagestructure.cpp" diff --git a/src/kpackage/packagestructure.h b/src/kpackage/packagestructure.h index 2edf8e4..2752c38 100644 --- a/src/kpackage/packagestructure.h +++ b/src/kpackage/packagestructure.h @@ -1,139 +1,126 @@ -/****************************************************************************** -* Copyright 2011 by Aaron Seigo * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2011 Aaron Seigo + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef KPACKAGE_PACKAGESTRUCTURE_H #define KPACKAGE_PACKAGESTRUCTURE_H #include #include #include #include #include namespace KPackage { class PackageStructurePrivate; /** * @class PackageStructure kpackage/packagestructure.h * * This class is used to define the filesystem structure of a package type. * A PackageStructure is implemented as a dynamically loaded plugin, in the reimplementation * of initPackage the allowed fines and directories in the package are set into the package, * for instance: * * @code * package->addFileDefinition("mainscript", QStringLiteral("ui/main.qml"), i18n("Main Script File")); * package->setDefaultPackageRoot(QStringLiteral("plasma/wallpapers/")); * package->addDirectoryDefinition("images", QStringLiteral("images"), i18n("Images")); * package->addDirectoryDefinition("theme", QStringLiteral("theme"), i18n("Themed Images")); * QStringList mimetypes; * mimetypes << QStringLiteral("image/svg+xml") << QStringLiteral("image/png") << QStringLiteral("image/jpeg"); * package->setMimeTypes("images", mimetypes); * @endcode * * @author Aaron Seigo */ class KPACKAGE_EXPORT PackageStructure : public QObject { Q_OBJECT public: explicit PackageStructure(QObject *parent = nullptr, const QVariantList &args = QVariantList()); ~PackageStructure(); /** * Called when a the PackageStructure should initialize a Package with the initial * structure. This allows setting paths before setPath is called. * * Note: one special value is "metadata" which can be set to the location of KPluginMetaData * compatible .desktop file within the package. If not defined, it is assumed that this file * exists under the top level directory of the package. * * @param package the Package to set up. The object is empty of all definition when * first passed in. */ virtual void initPackage(Package *package); /** * Called whenever the path changes so that subclasses may take * package specific actions. */ virtual void pathChanged(Package *package); /** * Installs a package matching this package structure. By default installs a * native KPackage::Package. * * @param package the instance of Package that is being used for the install; useful for * accessing file paths * @param archivePath path to the package archive file * @param packageRoot path to the directory where the package should be * installed to * @return KJob* to track the installation status **/ virtual KJob *install(Package *package, const QString &archivePath, const QString &packageRoot); /** * Updates a package matching this package structure. By default installs a * native KPackage::Package. If an older version is already installed, * it removes the old one. If the installed one is newer, * an error will occur. * * @param package the instance of Package that is being used for the install; useful for * accessing file paths * @param archivePath path to the package archive file * @param packageRoot path to the directory where the package should be * installed to * @return KJob* to track the installation status * @since 5.17 **/ virtual KJob *update(Package *package, const QString &archivePath, const QString &packageRoot); /** * Uninstalls a package matching this package structure. * * @param package the instance of Package that is being used for the install; useful for * accessing file paths * @param packageName the name of the package to remove * @param packageRoot path to the directory where the package should be installed to * @return KJob* to track the installation status */ virtual KJob *uninstall(Package *package, const QString &packageRoot); private: PackageStructurePrivate *d; }; } // KPackage namespace /** * Register a Package class when it is contained in a loadable module */ #define K_EXPORT_KPACKAGE_PACKAGE_WITH_JSON(classname, jsonFile) \ K_PLUGIN_FACTORY_WITH_JSON(factory, jsonFile, registerPlugin();) \ K_EXPORT_PLUGIN_VERSION(PACKAGE_VERSION) #endif diff --git a/src/kpackage/private/package_p.h b/src/kpackage/private/package_p.h index 148c87b..66cd366 100644 --- a/src/kpackage/private/package_p.h +++ b/src/kpackage/private/package_p.h @@ -1,114 +1,102 @@ /* - * Copyright © 2009 Rob Scheepmaker - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License version 2 as - * published by the Free Software Foundation - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ + SPDX-FileCopyrightText: 2009 Rob Scheepmaker + + SPDX-License-Identifier: LGPL-2.0-only +*/ #ifndef KPACKAGE_PACKAGE_P_H #define KPACKAGE_PACKAGE_P_H #include "../package.h" #include #include #include #include #include #include namespace KPackage { //KPackage is is normally used on the stack, explicitly shared and isn't a QObject //however PackageJob is given a pointer, which could be deleted at any moment //leaving the PackageJob with a dangling pointer //we need some way to invalidate the Package* pointer if it gets deleted //we can't just take a copy in the packagejob as we need to detach and update the *original* KPackage object //without changing anything else which happened to share the same KPackage::d //TODO KF6 - make KPackage::install()'s KJob return a new Package copy rather than modify //an existing object. class PackageDeletionNotifier : public QObject { Q_OBJECT public: static PackageDeletionNotifier* self(); Q_SIGNALS: void packageDeleted(Package *package); }; class ContentStructure { public: ContentStructure() : directory(false), required(false) { } ContentStructure(const ContentStructure &other) { paths = other.paths; name = other.name; mimeTypes = other.mimeTypes; directory = other.directory; required = other.required; } ContentStructure& operator=(const ContentStructure &) = default; QStringList paths; QString name; QStringList mimeTypes; bool directory : 1; bool required : 1; }; class PackagePrivate : public QSharedData { public: PackagePrivate(); PackagePrivate(const PackagePrivate &other); ~PackagePrivate(); PackagePrivate &operator=(const PackagePrivate &rhs); void createPackageMetadata(const QString &path); QString unpack(const QString &filePath); void updateHash(const QString &basePath, const QString &subPath, const QDir &dir, QCryptographicHash &hash); QString fallbackFilePath(const QByteArray &key, const QString &filename = QString()) const; bool hasCycle(const KPackage::Package &package); bool isInsidePackageDir(const QString& canonicalPath) const; QPointer structure; QString path; QString tempRoot; QStringList contentsPrefixPaths; QString defaultPackageRoot; QHash discoveries; QHash contents; Package *fallbackPackage; QStringList mimeTypes; KPluginMetaData *metadata; QString rccPath; bool externalPaths : 1; bool valid : 1; bool checkedValid : 1; }; } #endif diff --git a/src/kpackage/private/packagejob.cpp b/src/kpackage/private/packagejob.cpp index 9be5c65..c50ae4c 100644 --- a/src/kpackage/private/packagejob.cpp +++ b/src/kpackage/private/packagejob.cpp @@ -1,131 +1,118 @@ -/****************************************************************************** -* Copyright 2012 Sebastian Kügler * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2012 Sebastian Kügler + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "packagejob_p.h" #include "packagejobthread_p.h" #include "config-package.h" #include "package_p.h" #include "kpackage_debug.h" #include #include namespace KPackage { class PackageJobPrivate { public: PackageJobThread *thread; Package *package; QString installPath; }; PackageJob::PackageJob(Package *package, QObject *parent) : KJob(parent) { d = new PackageJobPrivate; d->thread = new PackageJobThread(this); d->package = package; connect(PackageDeletionNotifier::self(), &PackageDeletionNotifier::packageDeleted, this, [this](Package *package) { if (package == d->package) { d->package = nullptr; } }); connect(d->thread, &PackageJobThread::installPathChanged, this, [this](const QString &installPath) { if (d->package) { d->package->setPath(installPath); } emit installPathChanged(installPath); }, Qt::QueuedConnection); } PackageJob::~PackageJob() { delete d; } void PackageJob::slotFinished(bool ok, const QString &err) { if (ok) { setError(NoError); } else { setError(d->thread->errorCode()); setErrorText(err); } d->thread->exit(0); emitResult(); } void PackageJob::start() { d->thread->start(); } void PackageJob::install(const QString &src, const QString &dest) { const QString pluginId = d->package->metadata().pluginId(); const QStringList serviceTypes = d->package->metadata().serviceTypes(); //d-package can become dangling during the job if deleted externally connect(d->thread, &PackageJobThread::finished, this, [=](bool ok, const QString &error) { if (ok) { for (auto& packageType: serviceTypes) { auto msg = QDBusMessage::createSignal(QStringLiteral("/KPackage/") + packageType, QStringLiteral("org.kde.plasma.kpackage"), QStringLiteral("packageInstalled")); msg.setArguments({pluginId}); QDBusConnection::sessionBus().send(msg); } } slotFinished(ok, error); }, Qt::QueuedConnection); d->thread->install(src, dest); } void PackageJob::update(const QString &src, const QString &dest) { connect(d->thread, &PackageJobThread::finished, this, [=](bool ok, const QString &error) { slotFinished(ok, error); }, Qt::QueuedConnection); d->thread->update(src, dest); } void PackageJob::uninstall(const QString &installationPath) { //capture first as uninstalling wipes d->package const QString pluginId = d->package->metadata().pluginId(); const QStringList serviceTypes = d->package->metadata().serviceTypes(); connect(d->thread, &PackageJobThread::finished, this, [=](bool ok, const QString &error) { if (ok) { for (auto& packageType: serviceTypes) { auto msg = QDBusMessage::createSignal(QStringLiteral("/KPackage/") + packageType, QStringLiteral("org.kde.plasma.kpackage"), QStringLiteral("packageUninstalled")); msg.setArguments({pluginId}); QDBusConnection::sessionBus().send(msg); } } slotFinished(ok, error); }, Qt::QueuedConnection); d->thread->uninstall(installationPath); } } // namespace KPackage #include "moc_packagejob_p.cpp" diff --git a/src/kpackage/private/packagejob_p.h b/src/kpackage/private/packagejob_p.h index e8a3431..bf98b72 100644 --- a/src/kpackage/private/packagejob_p.h +++ b/src/kpackage/private/packagejob_p.h @@ -1,60 +1,47 @@ -/****************************************************************************** -* Copyright 2012 Sebastian Kügler * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2012 Sebastian Kügler + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef KPACKAGE_PACKAGEJOB_P_H #define KPACKAGE_PACKAGEJOB_P_H #include "kjob.h" namespace KPackage { class PackageJobPrivate; class Package; class PackageJob : public KJob { Q_OBJECT public: PackageJob(Package *package, QObject *parent = nullptr); ~PackageJob() override; void start() override; void install(const QString &src, const QString &dest); void update(const QString &src, const QString &dest); void uninstall(const QString &installationPath); Q_SIGNALS: void installPathChanged(const QString &path); // Q_SIGNALS: // void finished(bool success); private Q_SLOTS: void slotFinished(bool ok, const QString &err); private: PackageJobPrivate *d; }; } #endif diff --git a/src/kpackage/private/packagejobthread.cpp b/src/kpackage/private/packagejobthread.cpp index 9b157ac..2a1b806 100644 --- a/src/kpackage/private/packagejobthread.cpp +++ b/src/kpackage/private/packagejobthread.cpp @@ -1,476 +1,463 @@ -/****************************************************************************** -* Copyright 2007-2009 by Aaron Seigo * -* Copyright 2012 Sebastian Kügler * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007-2009 Aaron Seigo + SPDX-FileCopyrightText: 2012 Sebastian Kügler + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "private/packagejobthread_p.h" #include "package.h" #include "config-package.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kpackage_debug.h" namespace KPackage { bool copyFolder(QString sourcePath, QString targetPath) { QDir source(sourcePath); if (!source.exists()) { return false; } QDir target(targetPath); if (!target.exists()) { QString targetName = target.dirName(); target.cdUp(); target.mkdir(targetName); target = QDir(targetPath); } const auto lstEntries = source.entryList(QDir::Files); for (const QString &fileName : lstEntries) { QString sourceFilePath = sourcePath + QDir::separator() + fileName; QString targetFilePath = targetPath + QDir::separator() + fileName; if (!QFile::copy(sourceFilePath, targetFilePath)) { return false; } } const auto lstEntries2 = source.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); for (const QString &subFolderName : lstEntries2) { QString sourceSubFolderPath = sourcePath + QDir::separator() + subFolderName; QString targetSubFolderPath = targetPath + QDir::separator() + subFolderName; if (!copyFolder(sourceSubFolderPath, targetSubFolderPath)) { return false; } } return true; } bool removeFolder(QString folderPath) { QDir folder(folderPath); return folder.removeRecursively(); } bool removeIndex(const QString& dir) { bool ok = true; QFileInfo fileInfo(dir, QStringLiteral("kpluginindex.json")); if (fileInfo.exists()) { if (fileInfo.isWritable()) { QFile f(fileInfo.absoluteFilePath()); if (!f.remove()) { ok = false; qCWarning(KPACKAGE_LOG) << "Cannot remove kplugin index file: " << fileInfo.absoluteFilePath(); } else { qCDebug(KPACKAGE_LOG) << "Deleted index: " << fileInfo.absoluteFilePath(); } } else { qCWarning(KPACKAGE_LOG) << "Cannot remove kplugin index file (not writable): " << fileInfo.absoluteFilePath(); ok = false; } } return ok; } Q_GLOBAL_STATIC_WITH_ARGS(QStringList, metaDataFiles, (QStringList(QLatin1String("metadata.desktop")) << QLatin1String("metadata.json"))) bool indexDirectory(const QString& dir, const QString& dest) { QVariantMap vm; vm[QStringLiteral("Version")] = QStringLiteral("1.0"); vm[QStringLiteral("Timestamp")] = QDateTime::currentMSecsSinceEpoch(); QJsonArray plugins; QDirIterator it(dir, *metaDataFiles, QDir::Files, QDirIterator::Subdirectories); while (it.hasNext()) { it.next(); const QString path = it.fileInfo().absoluteFilePath(); QJsonObject obj = KPluginMetaData(path).rawData(); obj.insert(QStringLiteral("FileName"), path); plugins.append(obj); } // Less than two plugin means it's not worth indexing if (plugins.count() < 2) { removeIndex(dir); return true; } QString destfile = dest; if (!QDir::isAbsolutePath(dest)) { destfile = dir + QLatin1Char('/') + dest; } QDir().mkpath(QFileInfo(destfile).dir().absolutePath()); KCompressionDevice file(destfile, KCompressionDevice::BZip2); if (!file.open(QIODevice::WriteOnly)) { qCWarning(KPACKAGE_LOG) << "Failed to open " << destfile; return false; } QJsonDocument jdoc; jdoc.setArray(plugins); // file.write(jdoc.toJson()); file.write(jdoc.toBinaryData()); qCWarning(KPACKAGE_LOG) << "Generated " << destfile << " (" << plugins.count() << " plugins)"; return true; } class PackageJobThreadPrivate { public: QString installPath; QString errorMessage; int errorCode; }; PackageJobThread::PackageJobThread(QObject *parent) : QThread(parent) { d = new PackageJobThreadPrivate; d->errorCode = KJob::NoError; } PackageJobThread::~PackageJobThread() { delete d; } bool PackageJobThread::install(const QString &src, const QString &dest) { bool ok = installPackage(src, dest, Install); emit installPathChanged(d->installPath); emit finished(ok, d->errorMessage); return ok; } static QString resolveHandler(const QString &scheme) { QString candidatePath = QStringLiteral(CMAKE_INSTALL_FULL_LIBEXECDIR_KF5 "/kpackagehandlers/%1handler").arg(scheme); if (qEnvironmentVariableIsSet("KPACKAGE_DEP_RESOLVERS_PATH")) { candidatePath = QStringLiteral("%1/%2handler").arg(QString::fromUtf8(qgetenv("KPACKAGE_DEP_RESOLVERS_PATH")), scheme); } return QFile::exists(candidatePath) ? candidatePath : QString(); } bool PackageJobThread::installDependency(const QUrl &destUrl) { auto handler = resolveHandler(destUrl.scheme()); if (handler.isEmpty()) return false; QProcess process; process.setProgram(handler); process.setArguments({ destUrl.toString() }); process.setProcessChannelMode(QProcess::ForwardedChannels); process.start(); process.waitForFinished(); return process.exitCode() == 0; } bool PackageJobThread::installPackage(const QString &src, const QString &dest, OperationType operation) { QDir root(dest); if (!root.exists()) { QDir().mkpath(dest); if (!root.exists()) { d->errorMessage = i18n("Could not create package root directory: %1", dest); d->errorCode = Package::JobError::RootCreationError; //qCWarning(KPACKAGE_LOG) << "Could not create package root directory: " << dest; return false; } } QFileInfo fileInfo(src); if (!fileInfo.exists()) { d->errorMessage = i18n("No such file: %1", src); d->errorCode = Package::JobError::PackageFileNotFoundError; return false; } QString path; QTemporaryDir tempdir; bool archivedPackage = false; if (fileInfo.isDir()) { // we have a directory, so let's just install what is in there path = src; // make sure we end in a slash! if (!path.endsWith(QLatin1Char('/'))) { path.append(QLatin1Char('/')); } } else { KArchive *archive = nullptr; QMimeDatabase db; QMimeType mimetype = db.mimeTypeForFile(src); if (mimetype.inherits(QStringLiteral("application/zip"))) { archive = new KZip(src); } else if (mimetype.inherits(QStringLiteral("application/x-compressed-tar")) || mimetype.inherits(QStringLiteral("application/x-tar")) || mimetype.inherits(QStringLiteral("application/x-bzip-compressed-tar")) || mimetype.inherits(QStringLiteral("application/x-xz")) || mimetype.inherits(QStringLiteral("application/x-lzma"))) { archive = new KTar(src); } else { //qCWarning(KPACKAGE_LOG) << "Could not open package file, unsupported archive format:" << src << mimetype.name(); d->errorMessage = i18n("Could not open package file, unsupported archive format: %1 %2", src, mimetype.name()); d->errorCode = Package::JobError::UnsupportedArchiveFormatError; return false; } if (!archive->open(QIODevice::ReadOnly)) { //qCWarning(KPACKAGE_LOG) << "Could not open package file:" << src; delete archive; d->errorMessage = i18n("Could not open package file: %1", src); d->errorCode = Package::JobError::PackageOpenError; return false; } archivedPackage = true; path = tempdir.path() + QLatin1Char('/'); d->installPath = path; const KArchiveDirectory *source = archive->directory(); source->copyTo(path); QStringList entries = source->entries(); if (entries.count() == 1) { const KArchiveEntry *entry = source->entry(entries[0]); if (entry->isDirectory()) { path = path + entry->name() + QLatin1Char('/'); } } delete archive; } QDir packageDir(path); QFileInfoList entries = packageDir.entryInfoList(*metaDataFiles); KPluginMetaData meta; if (!entries.isEmpty()) { const QString metadataFilePath = entries.first().filePath(); if (metadataFilePath.endsWith(QLatin1String(".desktop"))) { meta = KPluginMetaData::fromDesktopFile(metadataFilePath, {QStringLiteral(":/kservicetypes5/kpackage-generic.desktop")}); } else { QFile f(metadataFilePath); if(!f.open(QIODevice::ReadOnly)){ qCWarning(KPACKAGE_LOG) << "Couldn't open metadata file" << src << path; d->errorMessage = i18n("Could not open metadata file: %1", src); d->errorCode = Package::JobError::MetadataFileMissingError; return false; } QJsonObject metadataObject = QJsonDocument::fromJson(f.readAll()).object(); meta = KPluginMetaData(metadataObject, QString(), metadataFilePath); } } if (!meta.isValid()) { qCDebug(KPACKAGE_LOG) << "No metadata file in package" << src << path; d->errorMessage = i18n("No metadata file in package: %1", src); d->errorCode = Package::JobError::MetadataFileMissingError; return false; } QString pluginName = meta.pluginId(); qCDebug(KPACKAGE_LOG) << "pluginname: " << meta.pluginId(); if (pluginName.isEmpty()) { //qCWarning(KPACKAGE_LOG) << "Package plugin name not specified"; d->errorMessage = i18n("Package plugin name not specified: %1", src); d->errorCode = Package::JobError::PluginNameMissingError; return false; } // Ensure that package names are safe so package uninstall can't inject // bad characters into the paths used for removal. const QRegularExpression validatePluginName(QStringLiteral("^[\\w\\-\\.]+$")); // Only allow letters, numbers, underscore and period. if (!validatePluginName.match(pluginName).hasMatch()) { //qCDebug(KPACKAGE_LOG) << "Package plugin name " << pluginName << "contains invalid characters"; d->errorMessage = i18n("Package plugin name %1 contains invalid characters", pluginName); d->errorCode = Package::JobError::PluginNameInvalidError; return false; } QString targetName = dest; if (targetName[targetName.size() - 1] != QLatin1Char('/')) { targetName.append(QLatin1Char('/')); } targetName.append(pluginName); if (QFile::exists(targetName)) { if (operation == Update) { KPluginMetaData oldMeta(targetName + QLatin1String("/metadata.desktop")); if (oldMeta.serviceTypes() != meta.serviceTypes()) { d->errorMessage = i18n("The new package has a different type from the old version already installed."); d->errorCode = Package::JobError::UpdatePackageTypeMismatchError; } else if (isVersionNewer(oldMeta.version(), meta.version())) { const bool ok = uninstallPackage(targetName); if (!ok) { d->errorMessage = i18n("Impossible to remove the old installation of %1 located at %2. error: %3", pluginName, targetName, d->errorMessage); d->errorCode = Package::JobError::OldVersionRemovalError; } } else { d->errorMessage = i18n("Not installing version %1 of %2. Version %3 already installed.", meta.version(), meta.pluginId(), oldMeta.version()); d->errorCode = Package::JobError::NewerVersionAlreadyInstalledError; } } else { d->errorMessage = i18n("%1 already exists", targetName); d->errorCode = Package::JobError::PackageAlreadyInstalledError; } if (d->errorCode != KJob::NoError) { d->installPath = targetName; return false; } } //install dependencies const QStringList dependencies = KPluginMetaData::readStringList(meta.rawData(), QStringLiteral("X-KPackage-Dependencies")); for(const QString &dep : dependencies) { QUrl depUrl(dep); if (!installDependency(depUrl)) { d->errorMessage = i18n("Could not install dependency: '%1'", dep); d->errorCode = Package::JobError::PackageCopyError; return false; } } if (archivedPackage) { // it's in a temp dir, so just move it over. const bool ok = copyFolder(path, targetName); removeFolder(path); if (!ok) { //qCWarning(KPACKAGE_LOG) << "Could not move package to destination:" << targetName; d->errorMessage = i18n("Could not move package to destination: %1", targetName); d->errorCode = Package::JobError::PackageMoveError; return false; } } else { // it's a directory containing the stuff, so copy the contents rather // than move them const bool ok = copyFolder(path, targetName); if (!ok) { //qCWarning(KPACKAGE_LOG) << "Could not copy package to destination:" << targetName; d->errorMessage = i18n("Could not copy package to destination: %1", targetName); d->errorCode = Package::JobError::PackageCopyError; return false; } } if (archivedPackage) { // no need to remove the temp dir (which has been successfully moved if it's an archive) tempdir.setAutoRemove(false); } indexDirectory(dest, QStringLiteral("kpluginindex.json")); d->installPath = targetName; return true; } bool PackageJobThread::update(const QString &src, const QString &dest) { bool ok = installPackage(src, dest, Update); emit installPathChanged(d->installPath); emit finished(ok, d->errorMessage); return ok; } bool PackageJobThread::uninstall(const QString &packagePath) { bool ok = uninstallPackage(packagePath); //qCDebug(KPACKAGE_LOG) << "emit installPathChanged " << d->installPath; emit installPathChanged(QString()); //qCDebug(KPACKAGE_LOG) << "Thread: installFinished" << ok; emit finished(ok, d->errorMessage); return ok; } bool PackageJobThread::uninstallPackage(const QString &packagePath) { if (!QFile::exists(packagePath)) { d->errorMessage = i18n("%1 does not exist", packagePath); d->errorCode = Package::JobError::PackageFileNotFoundError; return false; } QString pkg; QString root; { // FIXME: remove, pass in packageroot, type and pluginName separately? QStringList ps = packagePath.split(QLatin1Char('/')); int ix = ps.count() - 1; if (packagePath.endsWith(QLatin1Char('/'))) { ix = ps.count() - 2; } pkg = ps[ix]; ps.pop_back(); root = ps.join(QLatin1Char('/')); } bool ok = removeFolder(packagePath); if (!ok) { d->errorMessage = i18n("Could not delete package from: %1", packagePath); d->errorCode = Package::JobError::PackageUninstallError; return false; } indexDirectory(root, QStringLiteral("kpluginindex.json")); return true; } Package::JobError PackageJobThread::errorCode() const { return static_cast(d->errorCode); } } // namespace KPackage #include "moc_packagejobthread_p.cpp" diff --git a/src/kpackage/private/packagejobthread_p.h b/src/kpackage/private/packagejobthread_p.h index 61346a9..b4d21f8 100644 --- a/src/kpackage/private/packagejobthread_p.h +++ b/src/kpackage/private/packagejobthread_p.h @@ -1,78 +1,65 @@ -/****************************************************************************** -* Copyright 2007-2009 by Aaron Seigo * -* Copyright 2012 Sebastian Kügler * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007-2009 Aaron Seigo + SPDX-FileCopyrightText: 2012 Sebastian Kügler + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef KPACKAGE_PACKAGEJOBTHREAD_P_H #define KPACKAGE_PACKAGEJOBTHREAD_P_H #include "kjob.h" #include "package.h" #include const static auto s_kpluginindex = QStringLiteral("kpluginindex.json"); namespace KPackage { class PackageJobThreadPrivate; bool indexDirectory(const QString& dir, const QString& dest); //true if version2 is more recent than version1 //TODO: replace with QVersionNumber when we will be able to depend from Qt 5.6 bool isVersionNewer(const QString &version1, const QString &version2); class PackageJobThread : public QThread { Q_OBJECT public: enum OperationType { Install, Update }; explicit PackageJobThread(QObject *parent = nullptr); virtual ~PackageJobThread(); bool install(const QString &src, const QString &dest); bool update(const QString &src, const QString &dest); bool uninstall(const QString &packagePath); Package::JobError errorCode() const; Q_SIGNALS: void finished(bool success, const QString &errorMessage = QString()); void percentChanged(int percent); void error(const QString &errorMessage); void installPathChanged(const QString &installPath); private: //OperationType says whether we want to install, update or any //new similar operation it will be expanded bool installDependency(const QUrl &src); bool installPackage(const QString &src, const QString &dest, OperationType operation); bool uninstallPackage(const QString &packagePath); PackageJobThreadPrivate *d; }; } #endif diff --git a/src/kpackage/private/packageloader_p.h b/src/kpackage/private/packageloader_p.h index 583eb73..752a2ff 100644 --- a/src/kpackage/private/packageloader_p.h +++ b/src/kpackage/private/packageloader_p.h @@ -1,60 +1,47 @@ /* - * Copyright 2010 Ryan Rix - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ + SPDX-FileCopyrightText: 2010 Ryan Rix + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef KPACKAGE_PACKAGELOADER_P_H #define KPACKAGE_PACKAGELOADER_P_H #include "packagestructure.h" #include namespace KPackage { class PackageLoaderPrivate { public: PackageLoaderPrivate() : isDefaultLoader(false), packageStructurePluginDir(QStringLiteral("kpackage/packagestructure")) { } static QSet knownCategories(); static QString parentAppConstraint(const QString &parentApp = QString()); static QSet s_customCategories; QHash > structures; bool isDefaultLoader; QString packageStructurePluginDir; // We only use this cache during start of the process to speed up many consecutive calls // After that, we're too afraid to produce race conditions and it's not that time-critical anyway // the 20 seconds here means that the cache is only used within 20sec during startup, after that, // complexity goes up and we'd have to update the cache in order to avoid subtle bugs // just not using the cache is way easier then, since it doesn't make *that* much of a difference, // anyway int maxCacheAge = 20; qint64 pluginCacheAge = 0; QHash> pluginCache; }; } #endif diff --git a/src/kpackage/private/packages.cpp b/src/kpackage/private/packages.cpp index b90c217..7349e75 100644 --- a/src/kpackage/private/packages.cpp +++ b/src/kpackage/private/packages.cpp @@ -1,95 +1,82 @@ -/****************************************************************************** -* Copyright 2007-2009 by Aaron Seigo * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007-2009 Aaron Seigo + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "packages_p.h" #include #include #include "kpackage/package.h" void ChangeableMainScriptPackage::initPackage(KPackage::Package *package) { package->addFileDefinition("mainscript", QStringLiteral("scripts/main.js"), i18n("Main Script File")); package->setRequired("mainscript", true); } QString ChangeableMainScriptPackage::mainScriptConfigKey() const { return QStringLiteral("X-KPackage-MainScript"); } void ChangeableMainScriptPackage::pathChanged(KPackage::Package *package) { if (package->path().isEmpty()) { return; } QString mainScript = package->metadata().value(mainScriptConfigKey()); if (mainScript.isEmpty()) { mainScript = package->metadata().value(QStringLiteral("X-Plasma-MainScript")); } if (!mainScript.isEmpty()) { package->addFileDefinition("mainscript", mainScript, i18n("Main Script File")); } } void GenericPackage::initPackage(KPackage::Package *package) { ChangeableMainScriptPackage::initPackage(package); package->setDefaultPackageRoot(QStringLiteral("kpackage" "/generic/")); package->addDirectoryDefinition("images", QStringLiteral("images"), i18n("Images")); package->addDirectoryDefinition("theme", QStringLiteral("theme"), i18n("Themed Images")); QStringList mimetypes; mimetypes << QStringLiteral("image/svg+xml") << QStringLiteral("image/png") << QStringLiteral("image/jpeg"); package->setMimeTypes("images", mimetypes); package->setMimeTypes("theme", mimetypes); package->addDirectoryDefinition("config", QStringLiteral("config"), i18n("Configuration Definitions")); mimetypes.clear(); mimetypes << QStringLiteral("text/xml"); package->setMimeTypes("config", mimetypes); package->addDirectoryDefinition("ui", QStringLiteral("ui"), i18n("User Interface")); package->addDirectoryDefinition("data", QStringLiteral("data"), i18n("Data Files")); package->addDirectoryDefinition("scripts", QStringLiteral("code"), i18n("Executable Scripts")); mimetypes.clear(); mimetypes << QStringLiteral("text/plain"); package->setMimeTypes("scripts", mimetypes); package->addDirectoryDefinition("translations", QStringLiteral("locale"), i18n("Translations")); } void GenericQMLPackage::initPackage(KPackage::Package *package) { GenericPackage::initPackage(package); package->addFileDefinition("mainscript", QStringLiteral("ui/main.qml"), i18n("Main UI File")); package->setRequired("mainscript", true); package->setDefaultPackageRoot(QStringLiteral("kpackage" "/genericqml/")); } diff --git a/src/kpackage/private/packages_p.h b/src/kpackage/private/packages_p.h index 2feb0fe..8a79e3b 100644 --- a/src/kpackage/private/packages_p.h +++ b/src/kpackage/private/packages_p.h @@ -1,50 +1,37 @@ -/****************************************************************************** -* Copyright 2007 by Aaron Seigo * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2007 Aaron Seigo + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef LIBS_KPACKAGE_PACKAGES_P_H #define LIBS_KPACKAGE_PACKAGES_P_H #include "kpackage/packagestructure.h" class ChangeableMainScriptPackage : public KPackage::PackageStructure { Q_OBJECT public: void initPackage(KPackage::Package *package) override; protected: virtual QString mainScriptConfigKey() const; void pathChanged(KPackage::Package *package) override; }; class GenericPackage : public ChangeableMainScriptPackage { Q_OBJECT public: void initPackage(KPackage::Package *package) override; }; class GenericQMLPackage : public GenericPackage { Q_OBJECT public: void initPackage(KPackage::Package *package) override; }; #endif // LIBS_KPACKAGE_PACKAGES_P_H diff --git a/src/kpackage/private/versionparser.cpp b/src/kpackage/private/versionparser.cpp index 2411d2a..dd166e1 100644 --- a/src/kpackage/private/versionparser.cpp +++ b/src/kpackage/private/versionparser.cpp @@ -1,51 +1,38 @@ -/****************************************************************************** -* Copyright 2015 Marco Martin * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2015 Marco Martin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "private/packagejobthread_p.h" #include "package.h" #include namespace KPackage { bool isVersionNewer(const QString &version1, const QString &version2) { if (version1 == version2) { return false; } const auto versionChunks = QVector::fromList(version2.split(QLatin1Char('.'))); const auto oldVersionChunks = QVector::fromList(version1.split(QLatin1Char('.'))); const int length = qMin(versionChunks.size(), oldVersionChunks.size()); for (int i = 0; i < length; ++i) { if (versionChunks[i] != oldVersionChunks[i]) { return versionChunks[i] > oldVersionChunks[i]; } } return versionChunks.size() > oldVersionChunks.size(); } } // namespace KPackage diff --git a/src/kpackage/version.cpp b/src/kpackage/version.cpp index 244e921..1fc9553 100644 --- a/src/kpackage/version.cpp +++ b/src/kpackage/version.cpp @@ -1,77 +1,64 @@ /* - * Copyright 2008 by Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ + SPDX-FileCopyrightText: 2008 Aaron Seigo + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include #include "kpackage_debug.h" namespace KPackage { unsigned int version() { return PACKAGE_VERSION; } unsigned int versionMajor() { return PACKAGE_VERSION_MAJOR; } unsigned int versionMinor() { return PACKAGE_VERSION_MINOR; } unsigned int versionRelease() { return PACKAGE_VERSION_PATCH; } const char *versionString() { return PACKAGE_VERSION_STRING; } bool isPluginVersionCompatible(unsigned int version) { if (version == quint32(-1)) { // unversioned, just let it through qCWarning(KPACKAGE_LOG) << "unversioned plugin detected, may result in instability"; return true; } // we require PACKAGE_VERSION_MAJOR and PACKAGE_VERSION_MINOR const quint32 minVersion = PACKAGE_MAKE_VERSION(PACKAGE_VERSION_MAJOR, 0, 0); const quint32 maxVersion = PACKAGE_MAKE_VERSION(PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, 60); if (version < minVersion || version > maxVersion) { #ifndef NDEBUG // qCDebug(KPACKAGE_LOG) << "plugin is compiled against incompatible KPackage version " << version // << "This build is compatible with" << PACKAGE_VERSION_MAJOR << ".0.0 (" << minVersion // << ") to" << PACKAGE_VERSION_STRING << "(" << maxVersion << ")"; #endif return false; } return true; } } // namespace diff --git a/src/kpackage/version.h b/src/kpackage/version.h index 4264458..b39b8ed 100644 --- a/src/kpackage/version.h +++ b/src/kpackage/version.h @@ -1,74 +1,61 @@ /* - * Copyright 2008 by Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ + SPDX-FileCopyrightText: 2008 Aaron Seigo + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef KPACKAGEVERSION_H #define KPACKAGEVERSION_H /** @file kpackage/version.h */ #include #include #define PACKAGE_MAKE_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c)) /** * Compile-time macro for checking the kpackage version. Not useful for * detecting the version of kpackage at runtime. */ #define PACKAGE_IS_VERSION(a,b,c) (PACKAGE_VERSION >= PACKAGE_MAKE_VERSION(a,b,c)) /** * Namespace for everything in kpackage */ namespace KPackage { /** * The runtime version of libkpackage */ KPACKAGE_EXPORT unsigned int version(); /** * The runtime major version of libkpackage */ KPACKAGE_EXPORT unsigned int versionMajor(); /** * The runtime major version of libkpackage */ KPACKAGE_EXPORT unsigned int versionMinor(); /** * The runtime major version of libkpackage */ KPACKAGE_EXPORT unsigned int versionRelease(); /** * The runtime version string of libkpackage */ KPACKAGE_EXPORT const char *versionString(); /** * Verifies that a plugin is compatible with plasma */ KPACKAGE_EXPORT bool isPluginVersionCompatible(unsigned int version); } // Plasma namespace #endif // multiple inclusion guard diff --git a/src/kpackagetool/kpackagetool.cpp b/src/kpackagetool/kpackagetool.cpp index 9bd3a94..736055f 100644 --- a/src/kpackagetool/kpackagetool.cpp +++ b/src/kpackagetool/kpackagetool.cpp @@ -1,809 +1,796 @@ -/****************************************************************************** -* Copyright 2008 Aaron Seigo * -* Copyright 2012-2017 Sebastian Kügler * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2008 Aaron Seigo + SPDX-FileCopyrightText: 2012-2017 Sebastian Kügler + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #include "kpackagetool.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "options.h" #include "../kpackage/config-package.h" //for the index creation function #include "../kpackage/private/packagejobthread_p.h" Q_GLOBAL_STATIC_WITH_ARGS(QTextStream, cout, (stdout)) Q_GLOBAL_STATIC_WITH_ARGS(QTextStream, cerr, (stderr)) static QVector listPackageTypes() { QStringList libraryPaths; const QString subDirectory = QStringLiteral("kpackage/packagestructure"); const auto lstPath = QCoreApplication::libraryPaths(); for (const QString &dir : lstPath) { QString d = dir + QDir::separator() + subDirectory; if (!d.endsWith(QDir::separator())) { d += QDir::separator(); } libraryPaths << d; } QVector offers; for (const QString &plugindir : qAsConst(libraryPaths)) { const QString &_ixfile = plugindir + s_kpluginindex; QFile indexFile(_ixfile); if (indexFile.exists()) { indexFile.open(QIODevice::ReadOnly); QJsonDocument jdoc = QJsonDocument::fromBinaryData(indexFile.readAll()); indexFile.close(); QJsonArray plugins = jdoc.array(); for (QJsonArray::const_iterator iter = plugins.constBegin(); iter != plugins.constEnd(); ++iter) { const QJsonObject obj = iter->toObject(); const QString candidate = obj.value(QStringLiteral("FileName")).toString(); offers << KPluginMetaData(obj, candidate); } } else { QVector plugins = KPluginLoader::findPlugins(plugindir); QVectorIterator iter(plugins); while (iter.hasNext()) { auto md = iter.next(); offers << md; } } } return offers; } namespace KPackage { class PackageToolPrivate { public: QString packageRoot; QString packageFile; QString package; QStringList pluginTypes; KPackage::Package installer; KPluginMetaData metadata; QString installPath; void output(const QString &msg); QStringList packages(const QStringList &types, const QString &path = QString()); void renderTypeTable(const QMap &plugins); void listTypes(); void coutput(const QString &msg); void cerror(const QString &msg); QCommandLineParser *parser; }; PackageTool::PackageTool(int &argc, char **argv, QCommandLineParser *parser) : QCoreApplication(argc, argv) { d = new PackageToolPrivate; d->parser = parser; QTimer::singleShot(0, this, &PackageTool::runMain); } PackageTool::~PackageTool() { delete d; } void PackageTool::runMain() { KPackage::PackageStructure structure; if (d->parser->isSet(Options::hash())) { const QString path = d->parser->value(Options::hash()); KPackage::Package package(&structure); package.setPath(path); const QString hash = QString::fromLocal8Bit(package.cryptographicHash(QCryptographicHash::Sha1)); if (hash.isEmpty()) { d->coutput(i18n("Failed to generate a Package hash for %1", path)); exit(9); } else { d->coutput(i18n("SHA1 hash for Package at %1: '%2'", package.path(), hash)); exit(0); } return; } if (d->parser->isSet(Options::listTypes())) { d->listTypes(); exit(0); return; } QString type = d->parser->value(Options::type()); d->pluginTypes.clear(); d->installer = Package(); if (d->parser->isSet(Options::remove())) { d->package = d->parser->value(Options::remove()); } else if (d->parser->isSet(Options::upgrade())) { d->package = d->parser->value(Options::upgrade()); } else if (d->parser->isSet(Options::install())) { d->package = d->parser->value(Options::install()); } else if (d->parser->isSet(Options::show())) { d->package = d->parser->value(Options::show()); } else if (d->parser->isSet(Options::appstream())) { d->package = d->parser->value(Options::appstream()); } if (!QDir::isAbsolutePath(d->package)) { d->packageFile = QDir(QDir::currentPath() + QLatin1Char('/') + d->package).absolutePath(); d->packageFile = QFileInfo(d->packageFile).canonicalFilePath(); if (d->parser->isSet(Options::upgrade())) { d->package = d->packageFile; } } else { d->packageFile = d->package; } if (!d->packageFile.isEmpty() && (!d->parser->isSet(Options::type()) || type.compare(i18nc("package type", "wallpaper"), Qt::CaseInsensitive) == 0 || type.compare(QLatin1String("wallpaper"), Qt::CaseInsensitive) == 0)) { // Check type for common plasma packages KPackage::Package package(&structure); QString serviceType; package.setPath(d->packageFile); if (package.isValid() && package.metadata().isValid()) { serviceType = package.metadata().value(QStringLiteral("X-Plasma-ServiceType")); if (serviceType.isEmpty() && !package.metadata().serviceTypes().isEmpty()) { serviceType = package.metadata().serviceTypes().first(); } } if (!serviceType.isEmpty()) { if (serviceType == QLatin1String("KPackage/Generic")) { type = QStringLiteral("KPackage/Generic"); } else { type = serviceType; //qDebug() << "fallthrough type is" << serviceType; } } } { PackageStructure *structure = PackageLoader::self()->loadPackageStructure(type); if (structure) { d->installer = Package(structure); } if (!d->installer.hasValidStructure()) { qWarning() << "Package type" << type << "not found"; } d->packageRoot = d->installer.defaultPackageRoot(); d->pluginTypes << type; } if (d->parser->isSet(Options::show())) { const QString pluginName = d->package; showPackageInfo(pluginName); return; } else if (d->parser->isSet(Options::appstream())) { const QString pluginName = d->package; showAppstreamInfo(pluginName); return; } if (d->parser->isSet(Options::list())) { d->packageRoot = findPackageRoot(d->package, d->packageRoot); d->coutput(i18n("Listing service types: %1 in %2", d->pluginTypes.join(QStringLiteral(", ")), d->packageRoot)); listPackages(d->pluginTypes, d->packageRoot); exit(0); } else if (d->parser->isSet(Options::generateIndex())) { recreateIndex(); exit(0); } else if (d->parser->isSet(Options::removeIndex())) { removeIndex(); exit(0); } else { // install, remove or upgrade if (!d->installer.isValid()) { d->installer = KPackage::Package(new KPackage::PackageStructure()); } d->packageRoot = findPackageRoot(d->package, d->packageRoot); if (d->parser->isSet(Options::remove()) || d->parser->isSet(Options::upgrade())) { QString pkgPath; for (const QString &t : qAsConst(d->pluginTypes)) { KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(t); pkg.setPath(d->package); if (pkg.isValid()) { pkgPath = pkg.path(); if (pkgPath.isEmpty() && !d->packageFile.isEmpty()) { pkgPath = d->packageFile; } continue; } } if (pkgPath.isEmpty()) { pkgPath = d->package; } if (d->parser->isSet(Options::upgrade())) { d->installer.setPath(d->package); } QString _p = d->packageRoot; if (!_p.endsWith(QLatin1Char('/'))) { _p.append(QLatin1Char('/')); } _p.append(d->package); d->installer.setDefaultPackageRoot(d->packageRoot); d->installer.setPath(pkgPath); if (!d->parser->isSet(Options::type())) { const auto lst = d->installer.metadata().serviceTypes(); for (const QString &st : lst) { if (!d->pluginTypes.contains(st)) { d->pluginTypes << st; } } } QString pluginName; if (d->installer.isValid()) { d->metadata = d->installer.metadata(); if (!d->metadata.isValid()) { pluginName = d->package; } else if (!d->metadata.isValid() && d->metadata.pluginId().isEmpty()) { // plugin name given in command line pluginName = d->package; } else { // Parameter was a plasma package, get plugin name from the package pluginName = d->metadata.pluginId(); } } QStringList installed = d->packages(d->pluginTypes); if (QFile::exists(d->packageFile)) { d->installer.setPath(d->packageFile); if (d->installer.isValid()) { if (d->installer.metadata().isValid()) { pluginName = d->installer.metadata().pluginId(); } } } // Uninstalling ... if (installed.contains(pluginName)) { // Assume it's a plugin name d->installer.setPath(pluginName); KJob *uninstallJob = d->installer.uninstall(pluginName, d->packageRoot); connect(uninstallJob, SIGNAL(result(KJob*)), SLOT(packageUninstalled(KJob*))); return; } else { d->coutput(i18n("Error: Plugin %1 is not installed.", pluginName)); exit(2); } } if (d->parser->isSet(Options::install())) { KJob *installJob = d->installer.install(d->packageFile, d->packageRoot); connect(installJob, SIGNAL(result(KJob*)), SLOT(packageInstalled(KJob*))); return; } if (d->package.isEmpty()) { qWarning() << i18nc("No option was given, this is the error message telling the user he needs at least one, do not translate install, remove, upgrade nor list", "One of install, remove, upgrade or list is required."); exit(6); } } } void PackageToolPrivate::coutput(const QString &msg) { *cout << msg << '\n'; (*cout).flush(); } void PackageToolPrivate::cerror(const QString &msg) { *cerr << msg << '\n'; (*cerr).flush(); } QStringList PackageToolPrivate::packages(const QStringList &types, const QString &path) { QStringList result; for (const QString &type : types) { const QList services = KPackage::PackageLoader::self()->listPackages(type, path); for (const KPluginMetaData &service : services) { const QString _plugin = service.pluginId(); if (!result.contains(_plugin)) { result << _plugin; } } } return result; } void PackageTool::showPackageInfo(const QString &pluginName) { QString type = QStringLiteral("KPackage/Generic"); if (!d->pluginTypes.contains(type) && !d->pluginTypes.isEmpty()) { type = d->pluginTypes.at(0); } KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(type); pkg.setDefaultPackageRoot(d->packageRoot); if (QFile::exists(d->packageFile)) { pkg.setPath(d->packageFile); } else { pkg.setPath(pluginName); } KPluginMetaData i = pkg.metadata(); if (!i.isValid()) { *cerr << i18n("Error: Can't find plugin metadata: %1\n", pluginName); exit(3); return; } d->coutput(i18n("Showing info for package: %1", pluginName)); d->coutput(i18n(" Name : %1", i.name())); d->coutput(i18n(" Comment : %1", i.value(QStringLiteral("Comment")))); d->coutput(i18n(" Plugin : %1", i.pluginId())); auto const authors = i.authors(); d->coutput(i18n(" Author : %1", authors.first().name())); d->coutput(i18n(" Path : %1", pkg.path())); exit(0); } bool translateKPluginToAppstream(const QString &tagName, const QString &configField, const QJsonObject &configObject, QXmlStreamWriter& writer, bool canEndWithDot) { const QRegularExpression rx(QStringLiteral("%1\\[(.*)\\]").arg(configField)); const QJsonValue native = configObject.value(configField); if (native.isUndefined()) { return false; } QString content = native.toString(); if (!canEndWithDot && content.endsWith(QLatin1Char('.'))) { content.chop(1); } writer.writeTextElement(tagName, content); for (auto it = configObject.begin(), itEnd = configObject.end(); it != itEnd; ++it) { const auto match = rx.match(it.key()); if (match.hasMatch()) { QString content = it->toString(); if (!canEndWithDot && content.endsWith(QLatin1Char('.'))) { content.chop(1); } writer.writeStartElement(tagName); writer.writeAttribute(QStringLiteral("xml:lang"), match.captured(1)); writer.writeCharacters(content); writer.writeEndElement(); } } return true; } void PackageTool::showAppstreamInfo(const QString &pluginName) { KPluginMetaData i; //if the path passed is an absolute path, and a metadata file is found under it, use that metadata file to generate the appstream info. // This can happen in the case an application wanting to support kpackage based extensions includes in the same project both the packagestructure plugin and the packages themselves. In that case at build time the packagestructure plugin wouldn't be installed yet if (QFile::exists(pluginName + QStringLiteral("/metadata.desktop"))) { i = KPluginMetaData::fromDesktopFile(pluginName + QStringLiteral("/metadata.desktop"), {QStringLiteral(":/kservicetypes5/kpackage-generic.desktop")}); } else if (QFile::exists(pluginName + QStringLiteral("/metadata.json"))) { i = KPluginMetaData(pluginName + QStringLiteral("/metadata.json")); } else { QString type = QStringLiteral("KPackage/Generic"); if (!d->pluginTypes.contains(type) && !d->pluginTypes.isEmpty()) { type = d->pluginTypes.at(0); } KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(type); pkg.setDefaultPackageRoot(d->packageRoot); if (QFile::exists(d->packageFile)) { pkg.setPath(d->packageFile); } else { pkg.setPath(pluginName); } i = pkg.metadata(); } KPluginMetaData packageStructureMetaData; { const auto lst = listPackageTypes(); QString type; if (!i.serviceTypes().isEmpty()) { type = i.serviceTypes().constFirst(); } else { type = QStringLiteral("KPackage/Generic"); } for (const KPluginMetaData &md : lst) { if (md.pluginId() == type) { packageStructureMetaData = md; break; } } } if (!i.isValid()) { *cerr << i18n("Error: Can't find plugin metadata: %1\n", pluginName); std::exit(3); return; } QString parentApp = i.rawData().value(QLatin1String("X-KDE-ParentApp")).toString(); if (parentApp.isEmpty()) { parentApp = packageStructureMetaData.rawData().value(QLatin1String("X-KDE-ParentApp")).toString(); } const QJsonObject rootObject = i.rawData()[QStringLiteral("KPlugin")].toObject(); // Be super aggressive in finding a NoDisplay property. It can be a top-level property or // inside the KPlugin object, it also can be either a stringy type or a bool type. Try all // possible scopes and type conversions to find NoDisplay for (const auto& object : { i.rawData(), rootObject }) { if (object.value(QLatin1String("NoDisplay")).toBool(false) || // Standard value is unprocessed string we'll need to deal with. object.value(QLatin1String("NoDisplay")).toString() == QStringLiteral("true")) { std::exit(0); } } QXmlStreamAttributes componentAttributes; if (!parentApp.isEmpty()) { componentAttributes << QXmlStreamAttribute(QLatin1String("type"), QLatin1String("addon")); } // Compatibility: without appstream-metainfo-output argument we print the XML output to STDOUT // with the argument we'll print to the defined path. // TODO: in KF6 we should switch to argument-only. QIODevice *outputDevice = cout->device(); QScopedPointer outputFile; const auto outputPath = d->parser->value(Options::appstreamOutput()); if (!outputPath.isEmpty()) { auto outputUrl = QUrl::fromUserInput(outputPath); outputFile.reset(new QFile(outputUrl.toLocalFile())); if (!outputFile->open(QFile::WriteOnly | QFile::Text)) { *cerr << "Failed to open output file for writing."; exit(1); } outputDevice = outputFile.data(); } if (!rootObject.contains(QStringLiteral("Description"))) { *cerr << "Error: description missing, will result in broken appdata field as is mandatory at " << QFileInfo(i.metaDataFileName()).absoluteFilePath(); std::exit(10); } QXmlStreamWriter writer(outputDevice); writer.setAutoFormatting(true); writer.writeStartDocument(); writer.writeStartElement(QStringLiteral("component")); writer.writeAttributes(componentAttributes); writer.writeTextElement(QStringLiteral("id"), i.pluginId()); if (!parentApp.isEmpty()) { writer.writeTextElement(QStringLiteral("extends"), parentApp); } translateKPluginToAppstream(QStringLiteral("name"), QStringLiteral("Name"), rootObject, writer, false); translateKPluginToAppstream(QStringLiteral("summary"), QStringLiteral("Description"), rootObject, writer, false); if (!i.website().isEmpty()) { writer.writeStartElement(QStringLiteral("url")); writer.writeAttribute(QStringLiteral("type"), QStringLiteral("homepage")); writer.writeCharacters(i.website()); writer.writeEndElement(); } if (i.pluginId().startsWith(QLatin1String("org.kde."))) { writer.writeStartElement(QStringLiteral("url")); writer.writeAttribute(QStringLiteral("type"), QStringLiteral("donation")); writer.writeCharacters(QStringLiteral("https://www.kde.org/donate.php?app=%1").arg(i.pluginId())); writer.writeEndElement(); } const auto authors = i.authors(); if (!authors.isEmpty()) { QStringList authorsText; authorsText.reserve(authors.size()); for (const auto &author: authors) { authorsText += QStringLiteral("%1 <%2>").arg(author.name(), author.emailAddress()); } writer.writeTextElement(QStringLiteral("developer_name"), authorsText.join(QStringLiteral(", "))); } if (!i.iconName().isEmpty()) { writer.writeStartElement(QStringLiteral("icon")); writer.writeAttribute(QStringLiteral("type"), QStringLiteral("stock")); writer.writeCharacters(i.iconName()); writer.writeEndElement(); } writer.writeTextElement(QStringLiteral("project_license"), KAboutLicense::byKeyword(i.license()).spdx()); writer.writeTextElement(QStringLiteral("metadata_license"), QStringLiteral("CC0-1.0")); writer.writeEndElement(); writer.writeEndDocument(); exit(0); } QString PackageTool::findPackageRoot(const QString &pluginName, const QString &prefix) { Q_UNUSED(pluginName); Q_UNUSED(prefix); QString packageRoot; if (d->parser->isSet(Options::packageRoot()) && d->parser->isSet(Options::global()) && !d->parser->isSet(Options::generateIndex())) { qWarning() << i18nc("The user entered conflicting options packageroot and global, this is the error message telling the user he can use only one", "The packageroot and global options conflict with each other, please select only one."); ::exit(7); } else if (d->parser->isSet(Options::packageRoot())) { packageRoot = d->parser->value(Options::packageRoot()); //qDebug() << "(set via arg) d->packageRoot is: " << d->packageRoot; } else if (d->parser->isSet(Options::global())) { auto const paths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, d->packageRoot, QStandardPaths::LocateDirectory); if (!paths.isEmpty()) { packageRoot = paths.last(); } } else { packageRoot = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + d->packageRoot; } return packageRoot; } void PackageTool::listPackages(const QStringList &types, const QString &path) { QStringList list = d->packages(types, path); list.sort(); for (const QString &package : qAsConst(list)) { d->coutput(package); } exit(0); } void PackageToolPrivate::renderTypeTable(const QMap &plugins) { const QString nameHeader = i18n("Addon Name"); const QString pluginHeader = i18n("Service Type"); const QString pathHeader = i18n("Path"); int nameWidth = nameHeader.length(); int pluginWidth = pluginHeader.length(); int pathWidth = pathHeader.length(); QMapIterator pluginIt(plugins); while (pluginIt.hasNext()) { pluginIt.next(); if (pluginIt.key().length() > nameWidth) { nameWidth = pluginIt.key().length(); } if (pluginIt.value()[0].length() > pluginWidth) { pluginWidth = pluginIt.value()[0].length(); } if (pluginIt.value()[1].length() > pathWidth) { pathWidth = pluginIt.value()[1].length(); } } std::cout << nameHeader.toLocal8Bit().constData() << std::setw(nameWidth - nameHeader.length() + 2) << ' ' << pluginHeader.toLocal8Bit().constData() << std::setw(pluginWidth - pluginHeader.length() + 2) << ' ' << pathHeader.toLocal8Bit().constData() << std::setw(pathWidth - pathHeader.length() + 2) << ' ' << std::endl; std::cout << std::setfill('-') << std::setw(nameWidth) << '-' << " " << std::setw(pluginWidth) << '-' << " " << std::setw(pathWidth) << '-' << " " << std::endl; std::cout << std::setfill(' '); pluginIt.toFront(); while (pluginIt.hasNext()) { pluginIt.next(); std::cout << pluginIt.key().toLocal8Bit().constData() << std::setw(nameWidth - pluginIt.key().length() + 2) << ' ' << pluginIt.value()[0].toLocal8Bit().constData() << std::setw(pluginWidth - pluginIt.value()[0].length() + 2) << ' ' << pluginIt.value()[1].toLocal8Bit().constData() << std::setw(pathWidth - pluginIt.value()[1].length() + 2) << std::endl; } } void PackageToolPrivate::listTypes() { coutput(i18n("Package types that are installable with this tool:")); coutput(i18n("Built in:")); QMap builtIns; builtIns.insert(i18n("KPackage/Generic"), QStringList() << QStringLiteral("KPackage/Generic") << QStringLiteral(KPACKAGE_RELATIVE_DATA_INSTALL_DIR "/packages/")); builtIns.insert(i18n("KPackage/GenericQML"), QStringList() << QStringLiteral("KPackage/GenericQML") << QStringLiteral(KPACKAGE_RELATIVE_DATA_INSTALL_DIR "/genericqml/")); renderTypeTable(builtIns); const QVector offers = listPackageTypes(); if (!offers.isEmpty()) { std::cout << std::endl; coutput(i18n("Provided by plugins:")); QMap plugins; for (const KPluginMetaData &info : offers) { KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(info.pluginId()); QString name = info.name(); QString plugin = info.pluginId(); QString path = pkg.defaultPackageRoot(); plugins.insert(name, QStringList() << plugin << path); } renderTypeTable(plugins); } } void PackageTool::recreateIndex() { d->packageRoot = findPackageRoot(d->package, d->packageRoot); if (!QDir::isAbsolutePath(d->packageRoot)) { if (d->parser->isSet(Options::global())) { // Find package roots QStringList packageRoots; const QVector offers = listPackageTypes(); if (!offers.isEmpty()) { for (const KPluginMetaData &info : offers) { KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(info.pluginId()); const auto proot = pkg.defaultPackageRoot(); if (!proot.isEmpty()) { packageRoots << pkg.defaultPackageRoot(); } } } const auto lstPath = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, d->packageRoot, QStandardPaths::LocateDirectory); for (auto const &p : lstPath) { for (const auto &_proot: qAsConst(packageRoots)) { QFileInfo packageDirInfo(QStringLiteral("%1%2").arg(p, _proot)); if (!packageDirInfo.isWritable()) { continue; } const QString packagedir = packageDirInfo.absoluteFilePath(); if (KPackage::indexDirectory(packagedir, s_kpluginindex)) { d->coutput(i18n("Generating %1%2", packagedir, s_kpluginindex)); } else { d->cerror(i18n("Didn't write %1%2", packagedir, s_kpluginindex)); } } } return; } else { d->packageRoot = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + d->packageRoot; } } if (KPackage::indexDirectory(d->packageRoot, s_kpluginindex)) { d->coutput(i18n("Generating %1/%2", d->packageRoot, s_kpluginindex)); } else { d->cerror(i18n("Cannot write %1/%2", d->packageRoot, s_kpluginindex)); } } void PackageTool::removeIndex() { d->packageRoot = findPackageRoot(d->package, d->packageRoot); if (!QDir::isAbsolutePath(d->packageRoot)) { if (d->parser->isSet(Options::global())) { const auto lstEntries = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, d->packageRoot, QStandardPaths::LocateDirectory); for (auto const &p : lstEntries) { QDirIterator it(p, QStringList(s_kpluginindex), QDir::Files | QDir::Writable | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); qDebug() << "IX index remove" << p; while (it.hasNext()) { it.next(); const QString path = it.fileInfo().absoluteFilePath(); QFile file(path); if (!file.remove()) { d->cerror(i18n("Could not remove index file %1", file.fileName())); } else { d->coutput(i18n("Removed %1", file.fileName())); } } } return; } else { d->packageRoot = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + d->packageRoot; } } QFile file(d->packageRoot + s_kpluginindex); if (file.exists()) { if (!file.remove()) { d->cerror(i18n("Could not remove index file %1", file.fileName())); } else { d->coutput(i18n("Removed %1", file.fileName())); } } } void PackageTool::packageInstalled(KJob *job) { bool success = (job->error() == KJob::NoError); int exitcode = 0; if (success) { if (d->parser->isSet(Options::upgrade())) { d->coutput(i18n("Successfully upgraded %1", d->packageFile)); } else { d->coutput(i18n("Successfully installed %1", d->packageFile)); } } else { d->cerror(i18n("Error: Installation of %1 failed: %2", d->packageFile, job->errorText())); exitcode = 4; } exit(exitcode); } void PackageTool::packageUninstalled(KJob *job) { bool success = (job->error() == KJob::NoError); int exitcode = 0; if (success) { if (d->parser->isSet(Options::upgrade())) { d->coutput(i18n("Upgrading package from file: %1", d->packageFile)); KJob *installJob = d->installer.install(d->packageFile, d->packageRoot); connect(installJob, SIGNAL(result(KJob*)), SLOT(packageInstalled(KJob*))); return; } d->coutput(i18n("Successfully uninstalled %1", d->packageFile)); } else { d->cerror(i18n("Error: Uninstallation of %1 failed: %2", d->packageFile, job->errorText())); exitcode = 7; } exit(exitcode); } } // namespace KPackage #include "moc_kpackagetool.cpp" diff --git a/src/kpackagetool/kpackagetool.h b/src/kpackagetool/kpackagetool.h index 7abf6cb..cddfc6d 100644 --- a/src/kpackagetool/kpackagetool.h +++ b/src/kpackagetool/kpackagetool.h @@ -1,60 +1,47 @@ -/****************************************************************************** -* Copyright 2008 Aaron Seigo * -* Copyright 2012 Sebastian Kügler * -* * -* This library is free software; you can redistribute it and/or * -* modify it under the terms of the GNU Library General Public * -* License as published by the Free Software Foundation; either * -* version 2 of the License, or (at your option) any later version. * -* * -* This library is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * -* Library General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public License * -* along with this library; see the file COPYING.LIB. If not, write to * -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * -* Boston, MA 02110-1301, USA. * -*******************************************************************************/ +/* + SPDX-FileCopyrightText: 2008 Aaron Seigo + SPDX-FileCopyrightText: 2012 Sebastian Kügler + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ #ifndef PACKAGETOOL_H #define PACKAGETOOL_H #include class QCommandLineParser; class KJob; namespace KPackage { class PackageToolPrivate; class PackageTool : public QCoreApplication { Q_OBJECT public: PackageTool(int &argc, char **argv, QCommandLineParser *parser); virtual ~PackageTool(); void listPackages(const QStringList &types, const QString &path = QString()); void showPackageInfo(const QString &pluginName); void showAppstreamInfo(const QString &pluginName); QString findPackageRoot(const QString &pluginName, const QString &prefix); void recreateIndex(); void removeIndex(); private Q_SLOTS: void runMain(); void packageInstalled(KJob *job); void packageUninstalled(KJob *job); private: PackageToolPrivate *d; }; } #endif diff --git a/src/kpackagetool/main.cpp b/src/kpackagetool/main.cpp index 6413190..03fe239 100644 --- a/src/kpackagetool/main.cpp +++ b/src/kpackagetool/main.cpp @@ -1,84 +1,71 @@ /* - * Copyright 2008 Aaron Seigo - * Copyright 2013 Sebastian Kügler - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2, - * or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ + SPDX-FileCopyrightText: 2008 Aaron Seigo + SPDX-FileCopyrightText: 2013 Sebastian Kügler + + SPDX-License-Identifier: GPL-2.0-or-later +*/ /** * kpackagetool5 exit codes used in this program 0 No error 1 Unspecified error 2 Plugin is not installed 3 Plugin or package invalid 4 Installation failed, see stderr for reason 5 Could not find a suitable installer for package type 6 No install option given 7 Conflicting arguments supplied 8 Uninstallation failed, see stderr for reason 9 Failed to generate package hash */ #include #include #include "kpackagetool.h" #include "options.h" int main(int argc, char **argv) { QCommandLineParser parser; KPackage::PackageTool app(argc, argv, &parser); const QString description = i18n("KPackage Manager"); const auto version = QStringLiteral("2.0"); app.setApplicationVersion(version); parser.addVersionOption(); parser.addHelpOption(); parser.setApplicationDescription(description); parser.addOptions({ Options::hash(), Options::global(), Options::type(), Options::install(), Options::show(), Options::upgrade(), Options::list(), Options::listTypes(), Options::remove(), Options::packageRoot(), Options::generateIndex(), Options::removeIndex(), Options::appstream(), Options::appstreamOutput() }); parser.process(app); //at least one operation should be specified if (!parser.isSet(QStringLiteral("hash")) && !parser.isSet(QStringLiteral("g")) && !parser.isSet(QStringLiteral("i")) && !parser.isSet(QStringLiteral("s")) && !parser.isSet(QStringLiteral("appstream-metainfo")) && !parser.isSet(QStringLiteral("u")) && !parser.isSet(QStringLiteral("l")) && !parser.isSet(QStringLiteral("list-types")) && !parser.isSet(QStringLiteral("r")) && !parser.isSet(QStringLiteral("generate-index")) && !parser.isSet(QStringLiteral("remove-index"))) { parser.showHelp(0); } return app.exec(); }