chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Quintiq file version 2.0
#parent: #root
Method RecursiveDeleteSnapshots (
  LibOpt_Snapshot snapshot,
  Number number_to_delete
) as Number
{
  Description:
  [*
    Recursively walk the list of snapshots starting from the provided `LibOpt_Snapshot` and find snapshots that can be deleted.
    A snapshot that can be deleted is a snapshot without grand children.
    This is because deleting a child `LibOpt_Snapshot` would leave incomplete information underneath the parent `LibOpt_Snapshot`.
  *]
  TextBody:
  [*
    // benlong Mar-28-2022 (created)
    if( snapshot.CanAutoDelete() )
    {
      snapshotsBeforeDelete := this.Snapshot( relsize );
      snapshot.Delete();
      snapshotsAfterDelete := this.Snapshot( relsize );
      
      number_to_delete := number_to_delete - ( snapshotsBeforeDelete - snapshotsAfterDelete );
    }
    else
    {
      traverse( snapshot, Children, child, number_to_delete > 0 )
      {
        number_to_delete := this.RecursiveDeleteSnapshots( child, number_to_delete );
      }
    }
    return number_to_delete;
  *]
}