grr/test_lib/vfs_test_lib.py
def CreateFile(client_path, content=b"", token=None):
  """Creates a file in datastore-agnostic way.

  Args:
    client_path: A `ClientPath` instance specifying location of the file.
    content: A content to write to the file.
    token: A GRR token for accessing the data store.
  """
  precondition.AssertType(client_path, db.ClientPath)
  precondition.AssertType(content, bytes)

  blob_id = rdf_objects.BlobID.FromBlobData(content)

  stat_entry = rdf_client_fs.StatEntry(
      pathspec=rdf_paths.PathSpec(
          pathtype=client_path.path_type,
          path="/".join(client_path.components)),
      st_mode=33206,
      st_size=len(content))

  if data_store.RelationalDBWriteEnabled():
    data_store.BLOBS.WriteBlobs({blob_id: content})
    hash_id = file_store.AddFileWithUnknownHash(client_path, [blob_id])

    path_info = rdf_objects.PathInfo()
    path_info.path_type = client_path.path_type
    path_info.components = client_path.components
    path_info.hash_entry.num_bytes = len(content)
    path_info.hash_entry.sha256 = hash_id.AsBytes()
    path_info.stat_entry = stat_entry

    data_store.REL_DB.WritePathInfos(client_path.client_id, [path_info])

  urn = aff4.ROOT_URN.Add(client_path.client_id).Add(client_path.vfs_path)
  with aff4.FACTORY.Create(urn, aff4_grr.VFSBlobImage, token=token) as filedesc:
    bio = io.BytesIO()
    bio.write(content)
    bio.seek(0)

    filedesc.AppendContent(bio)
    filedesc.Set(filedesc.Schema.STAT, stat_entry)

    filedesc.Set(
        filedesc.Schema.HASH,
        rdf_crypto.Hash(
            sha256=rdf_objects.SHA256HashID.FromData(content).AsBytes(),
            num_bytes=len(content)))

    filedesc.Set(filedesc.Schema.CONTENT_LAST, rdfvalue.RDFDatetime.Now())
Creates a file in datastore-agnostic way.

  Args:
    client_path: A `ClientPath` instance specifying location of the file.
    content: A content to write to the file.
    token: A GRR token for accessing the data store.
  
Creates a file in datastore-agnostic way.
Creates a file in datastore - agnostic way .
def CreateFile(client_path, content=b"", token=None):
  precondition.AssertType(client_path, db.ClientPath)
  precondition.AssertType(content, bytes)
  blob_id = rdf_objects.BlobID.FromBlobData(content)
  stat_entry = rdf_client_fs.StatEntry(
      pathspec=rdf_paths.PathSpec(
          pathtype=client_path.path_type,
          path="/".join(client_path.components)),
      st_mode=33206,
      st_size=len(content))
  if data_store.RelationalDBWriteEnabled():
    data_store.BLOBS.WriteBlobs({blob_id: content})
    hash_id = file_store.AddFileWithUnknownHash(client_path, [blob_id])
    path_info = rdf_objects.PathInfo()
    path_info.path_type = client_path.path_type
    path_info.components = client_path.components
    path_info.hash_entry.num_bytes = len(content)
    path_info.hash_entry.sha256 = hash_id.AsBytes()
    path_info.stat_entry = stat_entry
    data_store.REL_DB.WritePathInfos(client_path.client_id, [path_info])
  urn = aff4.ROOT_URN.Add(client_path.client_id).Add(client_path.vfs_path)
  with aff4.FACTORY.Create(urn, aff4_grr.VFSBlobImage, token=token) as filedesc:
    bio = io.BytesIO()
    bio.write(content)
    bio.seek(0)
    filedesc.AppendContent(bio)
    filedesc.Set(filedesc.Schema.STAT, stat_entry)
    filedesc.Set(
        filedesc.Schema.HASH,
        rdf_crypto.Hash(
            sha256=rdf_objects.SHA256HashID.FromData(content).AsBytes(),
            num_bytes=len(content)))
    filedesc.Set(filedesc.Schema.CONTENT_LAST, rdfvalue.RDFDatetime.Now())
def CreateFile ( client_path , content = b"" , token = None ) : precondition . AssertType ( client_path , db . ClientPath ) precondition . AssertType ( content , bytes ) blob_id = rdf_objects . BlobID . FromBlobData ( content ) stat_entry = rdf_client_fs . StatEntry ( pathspec = rdf_paths . PathSpec ( pathtype = client_path . path_type , path = "/" . join ( client_path . components ) ) , st_mode = 33206 , st_size = len ( content ) ) if data_store . RelationalDBWriteEnabled ( ) : data_store . BLOBS . WriteBlobs ( { blob_id : content } ) hash_id = file_store . AddFileWithUnknownHash ( client_path , [ blob_id ] ) path_info = rdf_objects . PathInfo ( ) path_info . path_type = client_path . path_type path_info . components = client_path . components path_info . hash_entry . num_bytes = len ( content ) path_info . hash_entry . sha256 = hash_id . AsBytes ( ) path_info . stat_entry = stat_entry data_store . REL_DB . WritePathInfos ( client_path . client_id , [ path_info ] ) urn = aff4 . ROOT_URN . Add ( client_path . client_id ) . Add ( client_path . vfs_path ) with aff4 . FACTORY . Create ( urn , aff4_grr . VFSBlobImage , token = token ) as filedesc : bio = io . BytesIO ( ) bio . write ( content ) bio . seek ( 0 ) filedesc . AppendContent ( bio ) filedesc . Set ( filedesc . Schema . STAT , stat_entry ) filedesc . Set ( filedesc . Schema . HASH , rdf_crypto . Hash ( sha256 = rdf_objects . SHA256HashID . FromData ( content ) . AsBytes ( ) , num_bytes = len ( content ) ) ) filedesc . Set ( filedesc . Schema . CONTENT_LAST , rdfvalue . RDFDatetime . Now ( ) )
Creates a file in datastore-agnostic way.
Creates a file in datastore - agnostic way .
"""Creates a file in datastore-agnostic way.

  Args:
    client_path: A `ClientPath` instance specifying location of the file.
    content: A content to write to the file.
    token: A GRR token for accessing the data store.
  """
client_path
A `ClientPath` instance specifying location of the file.
A ` ClientPath ` instance specifying location of the file .
content
A content to write to the file.
A content to write to the file .
token
A GRR token for accessing the data store.
A GRR token for accessing the data store .