
    D                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  S
rSrSr\R                  \R                   " \R"                  R$                  5       " S S\R&                  5      5       5       r\R                  \R                   " \R"                  R*                  5       " S S\5      5       5       rg)zCImplementation of Unix-like mv command for cloud storage providers.    )absolute_import)division)unicode_literals)base)cp_command_util)errors)flags)storage_urla  
The mv command allows you to move data between your local file system and
the cloud, move data within the cloud, and move data between cloud storage
providers.

*Renaming Groups Of Objects*

You can use the mv command to rename all objects with a given prefix to
have a new prefix. For example, the following command renames all objects
under gs://my_bucket/oldprefix to be under gs://my_bucket/newprefix,
otherwise preserving the naming structure:

  $ {command} gs://my_bucket/oldprefix gs://my_bucket/newprefix

Note that when using mv to rename groups of objects with a common prefix,
you cannot specify the source URL using wildcards; you must spell out the
complete name.

If you do a rename as specified above and you want to preserve ACLs.

*Non-Atomic Operation*

Unlike the case with many file systems, the mv command does not perform a
single atomic operation. Rather, it performs a copy from source to
destination followed by removing the source for each object.

A consequence of this is that, in addition to normal network and operation
charges, if you move a Nearline Storage, Coldline Storage, or Archive
Storage object, deletion and data retrieval charges apply.
See the documentation for pricing details.
a  
To move all objects from a bucket to a local directory you could use:

  $ {command} gs://my_bucket/* dir

Similarly, to move all objects from a local directory to a bucket you
could use:

  $ {command} ./dir gs://my_bucket

The following command renames all objects under gs://my_bucket/oldprefix
to be under gs://my_bucket/newprefix, otherwise preserving the naming
structure:

  $ {command} gs://my_bucket/oldprefix gs://my_bucket/newprefix
z
The following command would clear all custom contexts from the destination
object while moving the object to the destination bucket.

  $ {command} gs://my-bucket/object gs://destination-bucket/object       --clear-custom-contexts
c                   8    \ rS rSrSr\\S.r\S 5       r	S r
Srg)MvS   Moves or renames objects.DESCRIPTIONEXAMPLESc                 x    [         R                  " XR                  5       5        [        R                  " U5        g )N)r   add_cp_and_mv_flagsReleaseTrackr	   add_per_object_retention_flags)clsparsers     lib/surface/storage/mv.pyArgsMv.Args]   s'    ''0@0@0BC	((0    c                 z   UR                    H  n[        R                  " U5      n[        U[        R                  5      (       a+  UR                  5       (       d  [        R                  " S5      eUR                  (       d  Mv  [        R                  " S5      e   SUl	        [        R                  " USS9U l        g )NzCannot mv buckets.zCannot mv stdin.T)delete_source)sourcer
   storage_url_from_string
isinstanceCloudUrl	is_objectr   InvalidUrlErroris_stdio	recursiver   run_cp	exit_code)selfargs
url_stringurls       r   RunMv.Runb   s    kk
//
;c	C--	.	.s}}$$%9::	$$%788 " DN$++DEDNr   )r'   N)__name__
__module____qualname____firstlineno____doc___COMMAND_DESCRIPTION_GA_EXAMPLESdetailed_helpclassmethodr   r,   __static_attributes__ r   r   r   r   S   s0     " *-
 1 1
Fr   r   c                   (    \ rS rSrSr\\\-   S.rSr	g)MvAlphao   r   r   r8   N)
r.   r/   r0   r1   r2   r3   r4   _ALPHA_EXAMPLESr5   r7   r8   r   r   r:   r:   o   s     " *0-r   r:   N)r2   
__future__r   r   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.storager   r   r	   r
   r3   r4   r<   UniverseCompatibleReleaseTracksr   GACommandr   ALPHAr:   r8   r   r   <module>rE      s    J &  ' ( > 5 4 : >  D%%(()F F * F4 D%%++,b  - r   