dvar = d.getVar('PKGD', True)
     pn = d.getVar('PN', True)
 
+    oldcwd = os.getcwd()
+    os.chdir(dvar)
+
     # We default to '.debug' style
     if d.getVar('PACKAGE_DEBUG_SPLIT_STYLE', True) == 'debug-file-directory':
         # Single debug-file-directory style debug info
     sourcefile = d.expand("${WORKDIR}/debugsources.list")
     bb.utils.remove(sourcefile)
 
-    os.chdir(dvar)
-
     # Return type (bits):
     # 0 - not elf
     # 1 - ELF
     #
     # End of strip
     #
+    os.chdir(oldcwd)
 }
 
 python populate_packages () {
     runtime_mapping_rename("RDEPENDS", pkg, d)
     runtime_mapping_rename("RRECOMMENDS", pkg, d)
     runtime_mapping_rename("RSUGGESTS", pkg, d)
-