# Buggy code
def install_targets(self, d):
    for t in d.targets:
        fname = check_for_stampfile(t.fname)
        outdir = get_destdir_path(d, t.outdir)
        outname = os.path.join(outdir, os.path.basename(fname))
        final_path = os.path.join(d.prefix, t.outdir, os.path.basename(fname))
        aliases = t.aliases
        should_strip = t.strip
        install_rpath = t.install_rpath
        install_name_mappings = t.install_name_mappings
        install_mode = t.install_mode
        d.dirmaker.makedirs(outdir, exist_ok=True)
        if not os.path.exists(fname):
            raise RuntimeError("File {!r} could not be found".format(fname))
        elif os.path.isfile(fname):
            self.do_copyfile(fname, outname)
            set_mode(outname, install_mode, d.install_umask)
            if should_strip and d.strip_bin is not None:
                if fname.endswith(".jar"):
                    print("Not stripping jar target:", os.path.basename(fname))
                    continue
                print("Stripping target {!r}".format(fname))
                ps, stdo, stde = Popen_safe(d.strip_bin + [outname])
                if ps.returncode != 0:
                    print("Could not strip file.\n")
                    print("Stdout:\n%s\n" % stdo)
                    print("Stderr:\n%s\n" % stde)
                    sys.exit(1)
            pdb_filename = os.path.splitext(fname)[0] + ".pdb"
            if not should_strip and os.path.exists(pdb_filename):
                pdb_outname = os.path.splitext(outname)[0] + ".pdb"
                self.do_copyfile(pdb_filename, pdb_outname)
                set_mode(pdb_outname, install_mode, d.install_umask)
        elif os.path.isdir(fname):
            fname = os.path.join(d.build_dir, fname.rstrip("/"))
            outname = os.path.join(outdir, os.path.basename(fname))
            self.do_copydir(d, fname, outname, None, install_mode)
        else:
            raise RuntimeError("Unknown file type for {!r}".format(fname))
        printed_symlink_error = False
        for alias, to in aliases.items():
            try:
                symlinkfilename = os.path.join(outdir, alias)
                try:
                    os.unlink(symlinkfilename)
                except FileNotFoundError:
                    pass
                os.symlink(to, symlinkfilename)
                append_to_log(self.lf, symlinkfilename)
            except (NotImplementedError, OSError):
                if not printed_symlink_error:
                    print(
                        "Symlink creation does not work on this platform. "
                        "Skipping all symlinking."
                    )
                    printed_symlink_error = True
        if os.path.isfile(outname):
            try:
                depfixer.fix_rpath(
                    outname,
                    install_rpath,
                    final_path,
                    install_name_mappings,
                    verbose=False,
                )
            except SystemExit as e:
                if isinstance(e.code, int) and e.code == 0:
                    pass
                else:
                    raise


# Traceback (FileNotFoundError)
Traceback (most recent call last):
File "d:\\projects\\cerbero\\meson\\master\\build\\build-tools\\Scripts\\meson.py", line 4, in <module>
__import__('pkg_resources').run_script('meson==0.47.0', 'meson.py')
File "c:\Python36-32\lib\site-packages\pkg_resources\__init__.py", line 658, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "c:\Python36-32\lib\site-packages\pkg_resources\__init__.py", line 1438, in run_script
exec(code, namespace, namespace)
File "d:\projects\cerbero\meson\master\build\build-tools\lib\site-packages\meson-0.47.0-py3.6.egg\EGG-INFO\scripts\meson.py", line 29, in <module>
sys.exit(mesonmain.main())
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\mesonmain.py", line 367, in main
return run(sys.argv[1:], launcher)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\mesonmain.py", line 281, in run
return minstall.run(remaining_args)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 466, in run
installer.do_install(datafilename)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 298, in do_install
self.install_targets(d)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 387, in install_targets
fname = check_for_stampfile(t.fname)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 170, in check_for_stampfile
if os.stat(fname).st_size == 0:
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'tls/gnutls\\giognutls.lib'
FAILED: meson-install
"c:\\Python36-32\\python.exe" "d:\\projects\\cerbero\\meson\\master\\build\\build-tools\\Scripts\\meson.py" "install" "--no-rebuild"
ninja: build stopped: subcommand failed.

# Fixed code
def install_targets(self, d):
    for t in d.targets:
        if not os.path.exists(t.fname):
            # For example, import libraries of shared modules are optional
            if t.optional:
                print("File {!r} not found, skipping".format(t.fname))
                continue
            else:
                raise RuntimeError("File {!r} could not be found".format(t.fname))
        fname = check_for_stampfile(t.fname)
        outdir = get_destdir_path(d, t.outdir)
        outname = os.path.join(outdir, os.path.basename(fname))
        final_path = os.path.join(d.prefix, t.outdir, os.path.basename(fname))
        aliases = t.aliases
        should_strip = t.strip
        install_rpath = t.install_rpath
        install_name_mappings = t.install_name_mappings
        install_mode = t.install_mode
        d.dirmaker.makedirs(outdir, exist_ok=True)
        if not os.path.exists(fname):
            raise RuntimeError("File {!r} could not be found".format(fname))
        elif os.path.isfile(fname):
            self.do_copyfile(fname, outname)
            set_mode(outname, install_mode, d.install_umask)
            if should_strip and d.strip_bin is not None:
                if fname.endswith(".jar"):
                    print("Not stripping jar target:", os.path.basename(fname))
                    continue
                print("Stripping target {!r}".format(fname))
                ps, stdo, stde = Popen_safe(d.strip_bin + [outname])
                if ps.returncode != 0:
                    print("Could not strip file.\n")
                    print("Stdout:\n%s\n" % stdo)
                    print("Stderr:\n%s\n" % stde)
                    sys.exit(1)
            pdb_filename = os.path.splitext(fname)[0] + ".pdb"
            if not should_strip and os.path.exists(pdb_filename):
                pdb_outname = os.path.splitext(outname)[0] + ".pdb"
                self.do_copyfile(pdb_filename, pdb_outname)
                set_mode(pdb_outname, install_mode, d.install_umask)
        elif os.path.isdir(fname):
            fname = os.path.join(d.build_dir, fname.rstrip("/"))
            outname = os.path.join(outdir, os.path.basename(fname))
            self.do_copydir(d, fname, outname, None, install_mode)
        else:
            raise RuntimeError("Unknown file type for {!r}".format(fname))
        printed_symlink_error = False
        for alias, to in aliases.items():
            try:
                symlinkfilename = os.path.join(outdir, alias)
                try:
                    os.unlink(symlinkfilename)
                except FileNotFoundError:
                    pass
                os.symlink(to, symlinkfilename)
                append_to_log(self.lf, symlinkfilename)
            except (NotImplementedError, OSError):
                if not printed_symlink_error:
                    print(
                        "Symlink creation does not work on this platform. "
                        "Skipping all symlinking."
                    )
                    printed_symlink_error = True
        if os.path.isfile(outname):
            try:
                depfixer.fix_rpath(
                    outname,
                    install_rpath,
                    final_path,
                    install_name_mappings,
                    verbose=False,
                )
            except SystemExit as e:
                if isinstance(e.code, int) and e.code == 0:
                    pass
                else:
                    raise