code: def _update_dir(c, dir, files, studies, series, storage_instances):
      logger.debug(f"Updating directory {dir}")
      c.execute(
          "SELECT name, mtime FROM file WHERE directory = ?", (dir,)
      )
      db_mtimes = dict(c)
      for fname in db_mtimes:
          if fname not in files:
              logger.debug(f"    remove {fname}")
              c.execute(
                  "DELETE FROM file WHERE directory = ? AND name = ?",
                  (dir, fname),
              )
      for fname in files:
          mtime = os.lstat(f"{dir}/{fname}").st_mtime
          if fname in db_mtimes and mtime <= db_mtimes[fname]:
              logger.debug(f"    okay {fname}")
          else:
              logger.debug(f"    update {fname}")
              si_uid = _update_file(
                  c, dir, fname, studies, series, storage_instances
              )
              if fname not in db_mtimes:
                  query = """INSERT INTO file (directory,
                                               name,
                                               mtime,
                                               storage_instance)
                             VALUES (?, ?, ?, ?)"""
                  c.execute(query, (dir, fname, mtime, si_uid))
              else:
                  query = """UPDATE file
                                SET mtime = ?, storage_instance = ?
                              WHERE directory = ? AND name = ?"""
                  c.execute(query, (mtime, si_uid, dir, fname))
  
imports: import contextlib
  import getpass
  import logging
  import os
  import sqlite3
  import tempfile
  import warnings
  from io import BytesIO
  from os.path import join
  import numpy
  from nibabel.optpkg import optional_package
  from .nifti1 import Nifti1Header
label_desc: Use image node_id 4 for calling a global function with example usage: _update_dir(c, dir, files, studies, series, storage_instances) without return types