{"action":"created","issue":{"url":"https://api.github.com/repos/sphinx-doc/testing2/issues/704","labels_url":"https://api.github.com/repos/sphinx-doc/testing2/issues/704/labels{/name}","comments_url":"https://api.github.com/repos/sphinx-doc/testing2/issues/704/comments","events_url":"https://api.github.com/repos/sphinx-doc/testing2/issues/704/events","html_url":"https://github.com/sphinx-doc/testing2/issues/704","id":53283340,"number":704,"title":"copy image as duplicates","user":{"login":"shimizukawa","id":151623,"avatar_url":"https://avatars.githubusercontent.com/u/151623?v=3","gravatar_id":"","url":"https://api.github.com/users/shimizukawa","html_url":"https://github.com/shimizukawa","followers_url":"https://api.github.com/users/shimizukawa/followers","following_url":"https://api.github.com/users/shimizukawa/following{/other_user}","gists_url":"https://api.github.com/users/shimizukawa/gists{/gist_id}","starred_url":"https://api.github.com/users/shimizukawa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shimizukawa/subscriptions","organizations_url":"https://api.github.com/users/shimizukawa/orgs","repos_url":"https://api.github.com/users/shimizukawa/repos","events_url":"https://api.github.com/users/shimizukawa/events{/privacy}","received_events_url":"https://api.github.com/users/shimizukawa/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sphinx-doc/testing2/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-01-02T22:42:06Z","updated_at":"2015-01-02T22:42:13Z","closed_at":"2015-01-02T22:42:07Z","body":"Hello all,\n\n\nI am making a website with plenty of figures, and I am very annoyed everytime I am running make html (or sphinx-build -b html -d _build/doctrees   . _build/html MY_RST_FILES).\n\nMy figures are in a complete different folder (i.e. outside the website folder or tree).\n\nWhen I run make html (or sphinx-build -b html -d _build/doctrees   . _build/html MY_RST_FILES), and the images have never been copied in _images before, then they are copied in it and everything is fine.\n\nBut when I run make html (or sphinx-build -b html -d _build/doctrees   . _build/html MY_RST_FILES), and the images have **already** been copied in _images before, then they are copied **again** and their name is change to fig_nameN.ext were N is an integer from 1 depending on how many duplicates are already there.\n\nThis was particularly annoying because of the time and storage waste.\n\nIn the module Sphinx-1.0.7-py2.5.egg/sphinx/util/osutil.py, I created a new function no_duplicate_copyfile:\n\n    \n    #!python\n    \n    import os\n    import stat\n    import time\n    import datetime\n    \n    def no_duplicate_copyfile(source, dest):\n        \"\"\"Copy a file and its modification times, if possible and if file is newer.\"\"\"\n        # if file does not exist: copy\n        if not os.path.exists(dest):\n            copyfile(source, dest)\n        # if file exist: check modification time\n        else:\n            # source\n            stat_source = os.stat(source)\n            year, month, day, hh, mm, ss = time.localtime(stat_source[stat.ST_MTIME])[:6]\n            modification_time_source = datetime.datetime(year, month, day, hh, mm, ss)\n            # dest\n            stat_dest = os.stat(dest)\n            year, month, day, hh, mm, ss = time.localtime(stat_dest[stat.ST_MTIME])[:6]\n            modification_time_dest = datetime.datetime(year, month, day, hh, mm, ss)\n            # old < new = True\n            # new < old = False\n            # if dest = older and source = newer, then copy\n            if modification_time_dest < modification_time_source:\n                copyfile(source, dest)\n    \n    \n\nMy problem is solved and I hope that this solution may help someone else. If another solution already existed, I'd be interested in knowing.\n\n\nThanks\nChristophe.\n\n----------------------------------------\n- Bitbucket: https://bitbucket.org/birkenfeld/sphinx/issue/704\n- Originally reported by: Anonymous\n- Originally created at: 2011-05-26T00:55:28.673\n"},"comment":{"url":"https://api.github.com/repos/sphinx-doc/testing2/issues/comments/68569691","html_url":"https://github.com/sphinx-doc/testing2/issues/704#issuecomment-68569691","issue_url":"https://api.github.com/repos/sphinx-doc/testing2/issues/704","id":68569691,"user":{"login":"shimizukawa","id":151623,"avatar_url":"https://avatars.githubusercontent.com/u/151623?v=3","gravatar_id":"","url":"https://api.github.com/users/shimizukawa","html_url":"https://github.com/shimizukawa","followers_url":"https://api.github.com/users/shimizukawa/followers","following_url":"https://api.github.com/users/shimizukawa/following{/other_user}","gists_url":"https://api.github.com/users/shimizukawa/gists{/gist_id}","starred_url":"https://api.github.com/users/shimizukawa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shimizukawa/subscriptions","organizations_url":"https://api.github.com/users/shimizukawa/orgs","repos_url":"https://api.github.com/users/shimizukawa/repos","events_url":"https://api.github.com/users/shimizukawa/events{/privacy}","received_events_url":"https://api.github.com/users/shimizukawa/received_events","type":"User","site_admin":false},"created_at":"2015-01-02T22:42:13Z","updated_at":"2015-01-02T22:42:13Z","body":"_From Georg Brandl on 2011-09-22 10:02:49+00:00_\n\nFix #704: image file duplication bug.\n\n→ \\<\\<cset 020daea23f09d445eb09607c6a6e0281c464ab9d\\>\\>"}}