require 'P4' # Rack middleware that cleans up any 'p4' handle added to the environment # during processing. # # This should always run, even in the face of exceptions. Make sure any # middleware configured after this step does *NOT* swallow exceptions. # # This expects that if a temporary workspace was generated, the 'p4_root' # variable was also added into the environment. See P4Helpers. class HWSP4Cleanup def initialize(app) @app = app end def call(env) ex = nil begin results = @app.call(env) rescue StandardError => e ex = e end # We need to convert any exception before attempting to delete, # otherwise the p4.messages and p4.errors will get reset at the next # method call. if ex.instance_of?(P4Exception) ex = Util.make_p4_error(p4) end if env.key?('p4') cleanup_p4(p4: env['p4'], p4_root: env['p4_root']) end raise ex unless ex.nil? results end def cleanup_p4(p4: nil, p4_root: nil) if p4 and p4.client != 'INVALID' p4.run_client('-d', p4.client) FileUtils.rmtree(p4_root) unless p4_root.nil? end p4.disconnect if p4 and p4.connected? end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 16196 | Doug Scheirer | Merge from main | ||
#1 | 15688 | Doug Scheirer |
Populate -o //guest/perforce_software/helix-web-services/... //guest/doug_scheirer/helix-web-services/.... |
||
//guest/perforce_software/helix-web-services/main/source/helix_web_services/lib/hws_p4_cleanup.rb | |||||
#1 | 15622 | tjuricek |
Move source code to 'source/' subdirectory of branch. build/ will remain where it is. |
||
//guest/perforce_software/helix-web-services/main/helix_web_services/lib/hws_p4_cleanup.rb | |||||
#3 | 15487 | tjuricek | Add basic ability to create pending changelists for helix sync projects. | ||
#2 | 15144 | tjuricek |
Setup stream spec tests and documentation. Also revised the documentation folder http_p4_web_api -> helix_versioning_engine |
||
#1 | 15032 | tjuricek |
Starting config and doc revisions. System is now broken while revisions underway. Configuration of the p4d connection is now done via a single HWSSettings middleware object injected into the Rack env. The HWSP4Cleanup middleware now cleans up any p4 injected into the Rack env. The Auth::App class now mostly just contains one method to generate a p4 ticket. /auth/v1/login. Added yard documentation for the main project. Yard docs have been reconfigured to dump into build/ directories. This should probably be done with each release. Hm... The top level rake file contains a task, 'all:doc', to update our documentation. This should probably be run for each checkin. Hm... Specs are now using Rack::Test on top of a 'live' p4d. I'd suggest you still use the p4util mechanism, which now dumps to a /tmp folder, so we can safely add P4IGNORE rules back into your local .p4config file. Old 'perforce' application now called 'helix_versioning_engine'. Removing cache data. Helix Sync may be slow. It may also get axed. We'll see. |