Howto remove empty dirs in post-deactivate?
Peter Danecek
Peter.Danecek at bo.ingv.it
Wed Apr 16 15:12:22 PDT 2014
On 16 Apr 2014, at 23:04, Ryan Schmidt <ryandesign at macports.org> wrote:
> On Apr 16, 2014, at 15:52, Peter Danecek wrote:
>
>> On 16 Apr 2014, at 22:41, Ryan Schmidt wrote:
>>
>>> On Apr 16, 2014, at 15:34, Peter Danecek wrote:
>>>
>>>> I am looking for an elegant way to remove some directory (directories) if they are empty in a Portfile.
>>>>
>>>> I would like to use this in the post-deactivate hook. There I remove some unregistered files, after related registered files are deactivated. However, afterwords I'd like to check if the dir now is empty and conditionally remove it.
>>>>
>>>> I am not very fluent in TCL, so any tip how to do this in an elegant way is welcome.
>>>
>>> MacPorts automatically removes empty directories from the destroot before installation. This is easy for it to do. It might be nice if there were a way for it to do the same post-
>>
>> The directories were registered, but are unregistered in the deactivate step, even if they are not removed because not (yet) empty, right?
>>
>> It would be most consistent to postpone this unregister step only after retrying to remove them after post-deactivate. Unfortunately, I do not know base too well. Would this be difficult to implement?
>
> Sorry, I was writing on my phone and managed to hit send before I was done.
This makes things clearer ;-)
> I was just musing that it’s easy for base to remove empty directories from the destroot directory before it creates the package tarball. But this isn’t so easy for it to do in the activate or deactivate phases when we no longer have a destroot.
Ok
> Also, MacPorts only registers files to active ports; it doesn’t register directories.
Right, I checked then ...
> My point was going to be that it would be nice if base handled this somehow for you; I wouldn’t want you to have to write too much code specific to this in every portfile where you wanted this behavior.
>
> On the other hand, this is apparently not a common need, or else it would have come up before now.
I'd agree that what I am doing with this special port (igtf-ca-bundle) is probably not a common use case, and I probably won't need this elsewhere.
>
> This is in contrast to the MacPorts function “delete” which is an alias for “file delete -force” and would remove non-empty directories.
>
> If “file delete” throws an error if the directory is non-empty, then you may have to wrap it in a catch.
I was not aware of the subtile difference with respect to the alias, and missed the catch wrap. I already did this (thanks to Joshua's mail), so this is done.
Now, however I came across a different issue. I realise I need to clean a cache directory as well. So I added the code below.
---
# purge fetch-crl cache
delete [ glob ${prefix}/var/cache/fetch-crl/*.state ]
---
The problem here is that the glob list becomes too long and the command fails on deactivations.
So how could I deal with this?
~petr
---
Error: org.macports.deactivate for port igtf-ca-bundle returned: /opt/local/var/cache/fetch-crl/AAACertificateServices.0.state /opt/local/var/cache/fetch-crl/AddTrust-External-CA-Root.0.state /opt/local/var/cache/fetch-crl/AEGIS.0.state /opt/local/var/cache/fetch-crl/ANSPGrid.0.state /opt/local/var/cache/fetch-crl/ArmeSFo.0.state /opt/local/var/cache/fetch-crl/ASGCCA-2007.0.state /opt/local/var/cache/fetch-crl/AustrianGrid.0.state /opt/local/var/cache/fetch-crl/BalticGrid.0.state /opt/local/var/cache/fetch-crl/BEGrid2008.0.state /opt/local/var/cache/fetch-crl/BG-ACAD-CA.0.state /opt/local/var/cache/fetch-crl/BrGrid.0.state /opt/local/var/cache/fetch-crl/BYGCA.0.state /opt/local/var/cache/fetch-crl/CALG.0.state /opt/local/var/cache/fetch-crl/CERN-GridCA.0.state /opt/local/var/cache/fetch-crl/CERN-Root-2.0.state /opt/local/var/cache/fetch-crl/CERN-Root.0.state /opt/local/var/cache/fetch-crl/CERN-TCA.0.state /opt/local/var/cache/fetch-crl/CESNET-CA-3.0.state /opt/local/var/cache/fetch-crl/CESNET-CA-Root.0.state /opt/local/var/cache/fetch-crl/cilogon-silver.0.state /opt/local/var/cache/fetch-crl/CNIC.0.state /opt/local/var/cache/fetch-crl/CNRS2-Grid-FR.0.state /opt/local/var/cache/fetch-crl/CNRS2-Projets.0.state /opt/local/var/cache/fetch-crl/CNRS2.0.state /opt/local/var/cache/fetch-crl/CyGrid.0.state /opt/local/var/cache/fetch-crl/DFN-GridGermany-Root.0.state /opt/local/var/cache/fetch-crl/DFN-SLCS.0.state /opt/local/var/cache/fetch-crl/DigiCertAssuredIDRootCA-Root.0.state /opt/local/var/cache/fetch-crl/DigiCertGridCA-1-Classic.0.state /opt/local/var/cache/fetch-crl/DigiCertGridCA-1G2-Classic.0.state /opt/local/var/cache/fetch-crl/DigiCertGridRootCA-Root.0.state /opt/local/var/cache/fetch-crl/DigiCertGridTrustCA-Classic.0.state /opt/local/var/cache/fetch-crl/DigiCertGridTrustCAG2-Classic.0.state /opt/local/var/cache/fetch-crl/DZeScience.0.state /opt/local/var/cache/fetch-crl/EG-GRID.0.state /opt/local/var/cache/fetch-crl/FNAL-SLCS.0.state /opt/local/var/cache/fetch-crl/GermanGrid.0.state /opt/local/var/cache/fetch-crl/GridCanada.0.state /opt/local/var/cache/fetch-crl/HellasGrid-CA-2006.0.state /opt/local/var/cache/fetch-crl/HellasGrid-Root.0.state /opt/local/var/cache/fetch-crl/HIAST.0.state /opt/local/var/cache/fetch-crl/HKU.0.state /opt/local/var/cache/fetch-crl/IGCA.0.state /opt/local/var/cache/fetch-crl/IHEP-2013.0.state /opt/local/var/cache/fetch-crl/IHEP.0.state /opt/local/var/cache/fetch-crl/INFN-CA-2006.0.state /opt/local/var/cache/fetch-crl/IRAN-GRID.0.state /opt/local/var/cache/fetch-crl/KEK.0.state /opt/local/var/cache/fetch-crl/KISTI-2007.0.state /opt/local/var/cache/fetch-crl/LACGridCA.0.state /opt/local/var/cache/fetch-crl/LIPCA.0.state /opt/local/var/cache/fetch-crl/MaGrid.0.state /opt/local/var/cache/fetch-crl/MARGI.0.state /opt/local/var/cache/fetch-crl/MD-Grid.0.state /opt/local/var/cache/fetch-crl/MREN-CA.0.state /opt/local/var/cache/fetch-crl/MYIFAM.0.state /opt/local/var/cache/fetch-crl/NAREGI.0.state /opt/local/var/cache/fetch-crl/NCHC.0.state /opt/local/var/cache/fetch-crl/NCSA-mics.0.state /opt/local/var/cache/fetch-crl/NCSA-slcs-2013.0.state /opt/local/var/cache/fetch-crl/NCSA-slcs.0.state /opt/local/var/cache/fetch-crl/NCSA-tfca-2013.0.state /opt/local/var/cache/fetch-crl/NCSA-tfca.0.state /opt/local/var/cache/fetch-crl/NECTEC.0.state /opt/local/var/cache/fetch-crl/NERSC-SLCS.0.state /opt/local/var/cache/fetch-crl/NICS-MyProxy.0.state /opt/local/var/cache/fetch-crl/NIIF.0.state /opt/local/var/cache/fetch-crl/NIKHEF.0.state /opt/local/var/cache/fetch-crl/NorduGrid.0.state /opt/local/var/cache/fetch-crl/PK-Grid-2007.0.state /opt/local/var/cache/fetch-crl/pkIRISGrid.0.state /opt/local/var/cache/fetch-crl/PolishGrid.0.state /opt/local/var/cache/fetch-crl/PRAGMA-UCSD.0.state /opt/local/var/cache/fetch-crl/PSC-Myproxy-CA.0.state /opt/local/var/cache/fetch-crl/QuoVadis-Root-CA1.0.state /opt/local/var/cache/fetch-crl/RDIG.0.state /opt/local/var/cache/fetch-crl/REUNA-ca.0.state /opt/local/var/cache/fetch-crl/RomanianGRID.0.state /opt/local/var/cache/fetch-crl/SDG.0.state /opt/local/var/cache/fetch-crl/SEE-GRID.0.state /opt/local/var/cache/fetch-crl/seegrid-ca-2013.0.state /opt/local/var/cache/fetch-crl/SiGNET-CA.0.state /opt/local/var/cache/fetch-crl/SlovakGrid.0.state /opt/local/var/cache/fetch-crl/SRCE.0.state /opt/local/var/cache/fetch-crl/SWITCH-QuoVadis-Grid-ICA.0.state /opt/local/var/cache/fetch-crl/TERENA-eScience-SSL-CA.0.state /opt/local/var/cache/fetch-crl/TERENAeSciencePersonalCA.0.state /opt/local/var/cache/fetch-crl/TRGrid.0.state /opt/local/var/cache/fetch-crl/UGRID.0.state /opt/local/var/cache/fetch-crl/UKeScienceCA-2A.0.state /opt/local/var/cache/fetch-crl/UKeScienceCA-2B.0.state /opt/local/var/cache/fetch-crl/UKeScienceRoot-2007.0.state /opt/local/var/cache/fetch-crl/ULAGrid-CA-2008.0.state /opt/local/var/cache/fetch-crl/UNAMgrid-ca.0.state /opt/local/var/cache/fetch-crl/UniandesCA.0.state /opt/local/var/cache/fetch-crl/UNLPGrid.0.state /opt/local/var/cache/fetch-crl/UTN-USERFirst-Hardware.0.state /opt/local/var/cache/fetch-crl/UTNAAAClient.0.state: file name too long
Warning: targets not executed for igtf-ca-bundle: org.macports.deactivate
Please see the log file for port igtf-ca-bundle for details:
/opt/local/var/macports/logs/_opt_local_var_macports_registry_portfiles_igtf-ca-bundle_1.56_0/igtf-ca-bundle/main.log
Warning: Failed to execute portfile from registry for igtf-ca-bundle @1.56_0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1762 bytes
Desc: not available
URL: <https://lists.macosforge.org/pipermail/macports-dev/attachments/20140417/5ac21f33/attachment-0001.p7s>
More information about the macports-dev
mailing list