Move path manipulations into function

Fixes: bug #1206670

Change-Id: I310429e390386e9201d1c9289732c51fca99c5f3
Merge "Move path manipulations into function"