diff --git a/wakatime/main.py b/wakatime/main.py index ac0eb81..41a5adf 100644 --- a/wakatime/main.py +++ b/wakatime/main.py @@ -471,6 +471,17 @@ def sync_offline_heartbeats(args, hostname): return SUCCESS +def format_file_path(filepath): + """Formats a path as absolute and with the correct platform separator.""" + + try: + filepath = os.path.realpath(os.path.abspath(filepath)) + filepath = re.sub(r'[/\\]', os.path.sep, filepath) + except: + pass + return filepath + + def process_heartbeat(args, configs, hostname, heartbeat): exclude = should_exclude(heartbeat['entity'], args.include, args.exclude) if exclude is not False: @@ -482,6 +493,9 @@ def process_heartbeat(args, configs, hostname, heartbeat): if heartbeat.get('entity_type') not in ['file', 'domain', 'app']: heartbeat['entity_type'] = 'file' + if heartbeat['entity_type'] == 'file': + heartbeat['entity'] = format_file_path(heartbeat['entity']) + if heartbeat['entity_type'] != 'file' or os.path.isfile(heartbeat['entity']): stats = get_file_stats(heartbeat['entity'],